zsh-users
 help / color / mirror / code / Atom feed
* automatically turn previous command into an alias
@ 2022-08-30  8:02 zzapper
  2022-08-30 13:04 ` Eric Cook
  0 siblings, 1 reply; 3+ messages in thread
From: zzapper @ 2022-08-30  8:02 UTC (permalink / raw)
  To: Zsh-Users List

[-- Attachment #1: Type: text/plain, Size: 396 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 1547 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: automatically turn previous command into an alias
  2022-08-30  8:02 automatically turn previous command into an alias zzapper
@ 2022-08-30 13:04 ` Eric Cook
  2022-08-30 13:26   ` zzapper
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Cook @ 2022-08-30 13:04 UTC (permalink / raw)
  To: zsh-users

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
}


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: automatically turn previous command into an alias
  2022-08-30 13:04 ` Eric Cook
@ 2022-08-30 13:26   ` zzapper
  0 siblings, 0 replies; 3+ messages in thread
From: zzapper @ 2022-08-30 13:26 UTC (permalink / raw)
  To: zsh-users


On 30/08/2022 14:04, Eric Cook wrote:
> On 8/30/22 04:02, zzapper wrote:
>>
>> # 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'
>>
>>
>>
>> any improvements, easier way etc
>>
>
> aliases_suck() {
>   aliases[${1:?no name given}]=$history[$((HISTCMD-1))]
>   alias -L $1
> }
>
I really like your elegant solution. My lingering preference for aliases 
is that they are so easy to tab expand and tweek


zzapper



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-30 13:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-30  8:02 automatically turn previous command into an alias zzapper
2022-08-30 13:04 ` Eric Cook
2022-08-30 13:26   ` zzapper

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).