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

Re: alias hygiene



On 2018-02-17 15:30:45 +0000, Daniel Shahaf wrote:
> Ray Andrews wrote on Sat, 17 Feb 2018 07:20 -0800:
> > Thanks.  There's a lot of homework in your post, I'll get on it. For now 
> > I take it that one can legitimately have an alias definition conditional 
> > on some test, at least in theory,
> 
> Yes.  Example:
> 
> case $OSNAME in
>   (linux*) alias ls='ls --color';;
>   (freebsd*) alias ls='ls -G';;
> esac

And I even have an alias generator that can redefine existing aliases:

use-pager()
{
  local -a cmd
  cmd=(pager-wrapper)
  while [[ $1 == -* ]]
  do
    cmd+=${(q)1}
    shift
  done
  local i
  for i in $@
  do
    whence $i > /dev/null &&
      alias $i="$cmd ${(Q)"${$(alias $i)#*=}":-$i}"
  done
}

I hope that's correct.

The goal is to alias commands to use a pager when possible
(the pager-wrapper function uses a pager only when the output
is sent to a terminal).

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



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