Open olivertzeng opened 8 months ago
That's tricky. Can you give it a stab to implement a solution?
That's tricky. Can you give it a stab to implement a solution?
I can't I'm not good at python enough. I might try though
That's tricky. Can you give it a stab to implement a solution?
@djui
There's a dumb stupid solution on the user side though You could just have another alias of
alias gp='g pull'
However that probably won't work since it still doesn't know what g is
But maybe this is the right way of solving this problem ig.
Because another solution I can think of is that you could just "sort it out" by taking out the first line of the alias and then search the others.
For example if you have an alias of
alias vim='nvim'
alias g='git'
alias please='sudo'
alias upg='sudo pacman -Syu'
alias gp='git push'
alias visudo='sudo nvim /etc/sudoers'
Let's say you have an array of aliases called a[n] for example a[0] for vim a[4] for gp and another copied array of aliased commands of b[n] So the shellscript should first have another empty two-dimensional array c[length of a and b][try to make it a tuple idk if shellscripts can do this or not] , after that the script fetches the first element of b and tries to search if any other elements b and c contains the word b[0]. If it does first replace the searched words with the alias(array a) and then put the result into array c[corresponding a element number][whatever]. (please don't judge my English I'm a Taiwanese sorry for that)
Using the same list of alias as an example. It'll first search for the word nvim inside other element s(except a) it'll find b[5] which is sudo nvim /etc/visudo
then it'll store the replaced value sudo vim /etc/visudo
inside c[5][0] and then b[1] for git, storing g pull
into c[4][0], searching for b[2] finding both c[5][0] b[3] b[5] and then stores please vim /etc/visudo
into c[5][1], please pacman -Syu
into b[3][0] and please nvim /etc/visudo
into c[5][2] so on.
After indexing remember to save the indexed array so the user will only have to do it once.
There's still one problem though, searching for array c might take an incredible amount of time and might be very efficient, however if you skip it you might miss out a lot of aliases just like before. So we should probably think of a better algorithm of searching these aliases.
Thanks for reading this!
for example I have two alias
alias g='git'
alias gp = 'git push'
and then if i do
g push
it won't show me the prompt that this is the same asgp