Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: automatically turn previous command into an alias



On 8/30/22 04:02, zzapper wrote:
Hi

# automatically turn previous command into an alias

 alias mkal='_f(){_al=$(history -n -1 -1 | sed "s#\\\\n##" ); alias $1="$_al" ; alias -L "$1"};_f'

 ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head

 mkal psq

 psq

PID PPID CMD %MEM %CPU

3393 2374 /usr/lib/firefox/firefox 10.0 3.6 119165

3364 /usr/lib/thunderbird/thunde 7.2 30.4

.. etc


any improvements, easier way etc


aliases_suck() {
  aliases[${1:?no name given}]=$history[$((HISTCMD-1))]
  alias -L $1
}




Messages sorted by: Reverse Date, Date, Thread, Author