I am trying to write an alias for cd !!: 1, which takes the second word of the previous command and changes the directory of that name. For example, if I type
rails new_project cd !!:1
the second line will be written to the "new_project" directory.
Since !!: 1 is inconvenient to type (although this is short, it requires three SHIFT keys, on opposite sides of the keyboard, and then an unSHIFTed version of the key that was printed twice SHIFTed), I just want to type something like
cd-
but since !!: 1 is evaluated on the command line, I (OBVIOUSLY) cannot just do
alias cd-=!!:1
or I would save an alias containing the "new_project" encoded in it. So I tried
alias cd-='!!:1'
The problem is that !!: 1 is NEVER evaluated, and I get a message stating that no directory named !!: 1 exists. How can I create an alias that evaluates the history substitution. At the time when I ask Alias ββcommand, and not when I define an alias, and not never?
(I tried this in both bash and zsh, and get the same results in both.)
bash eval alias zsh history
iconoclast
source share