Alias, a case for it

Table of Contents

1 Introduction

It's taken me a while to appreciate the use of the shell alias.

What's that?

The alias is a command short-hand. I'd resisted it's use since I believe the generality of the function was, in all cases, so simple as the equivalent alias. I've compromised with my more stringent self.

2 Features

I'm now maintaining an alias file, ~/.alias.rc with the following features:

  • save current aliases
  • finding functions I use and functions which use me
  • command shorthand
    • backup
    • declare
    • echo arguments
    • ls
    • pushd …
    • source (or ".")
    • type
  • alias creator pushd

3 Code

There is no code, as such. Here is the current ~/.alias.rc file:

alias Dropbox='ignore pushd /Users/applemcg/Dropbox; cleandirlist'
alias al='set $PWD; alias $(basename $(lc $1))="ignore pushd $1; cleandirlist"; sava'
alias bbf='backup $(backup_files); chmod +x *lib'
alias blog='pushd /Users/applemcg/Dropbox/marty3/m_c_wagon/src; cleandirlist'
alias ca='set cleandirlist; ga $1 ; ga -v $1'
alias commonplace='ignore pushd /Users/applemcg/Dropbox/commonplace; cleandirlist'
alias ea='echo $# $*'
alias filezilla='/Applications/Filezilla.app/Contents/MacOS/filezilla'
alias finance='ignore pushd /Users/applemcg/Dropbox/Family/finance; cleandirlist'
alias ftpm='. ftplib; ftp_set mcgowansorg ftp.mcgowans.org'
alias ftpr='ftp_many $(ftp_common) *.html *.css *.jpg *.txt'
alias ga='alias | grep '
alias i_use='fun_uses'
alias invest='ignore pushd /Users/applemcg/Dropbox/Family/invest; cleandirlist'
alias itc='ignore pushd /Users/applemcg/stonebridge/itc; cleandirlist'
alias ja='alias | sed '\''s/=.*//'\'''
alias js='ignore pushd /Users/applemcg/Dropbox/src/js; cleandirlist'
alias lbf='llrt $(backup_files)'
alias le='exa'
alias libmgmt='ignore pushd /Users/applemcg/Dropbox/src/libmgmt; cleandirlist'
alias llrt='ls -lrt'
alias meeting='ignore pushd /Users/applemcg/OneDrive/MensClub/2017_18/meeting; cleandirlist'
alias mensclub='ignore pushd /Users/applemcg/OneDrive/MensClub; cleandirlist'
alias q='quietly'
alias ra='. ~/.alias.rc'
alias rdput='rd_syncf'
alias reshoring='ignore pushd /Users/applemcg/Dropbox/reshoring; cleandirlist'
alias sava='(alias; echo alias) > ~/.alias.rc; alias'
alias sd='save_dirs'
alias sff='for f in *; do . $f ; echo === $f ===; done'
alias software='ignore pushd /Users/applemcg/Dropbox/commonplace/software; cleandirlist'
alias src='ignore pushd /Users/applemcg/git/src; cleandirlist'
alias ta='type -a'
alias textindex='ignore pushd /Users/applemcg/Dropbox/commonplace/textindex; cleandirlist'
alias trfn='sed '\''s/\/[^\/]*$//'\'''
alias txt='ignore pushd /Users/applemcg/Dropbox/Family/txt; cleandirlist'
alias use_me='fuse'
alias

4 Invoked

The alias file is invoked in the shell start-up, this line from ~/.bash_profile loads the aliases.

[[ -f ~/.alias.rc ]] && source ~/.alias.rc

5 Examples

5.1 al

The al alias is the pushd writer, and responsible for the aliases which use use that built-in to push the directory onto the stack and remove any duplicates. The current list:

  • blog – my now-deprecated blogging location
  • finance – and
  • invest – two directories which should be merged
  • js – where JavaScript development is taking place
  • resh - which was manually created, to be cleaned up as below, and
  • stone – which wasn't created with al, but started the cascade, breaking marty's threshold of three.

To see the current list:

$ alias | grep pushd

To reset the resh alias to the directory name:

$ resh; unalias resh; al

The alias is now reshoring, a bit longer, but that's the way to remember it.

5.2 ga

The shorthand for G\rep A\lias. Replace the above with

ga pushd

A conventient counterpart is ta, which checks for types. Before appropriatting a name as an alias, e.g.

ta ga

5.3 ja

The ja alias demonstrates the quoting escapes needed to put a sed command into an alias. In these cases, use a function to simplify the code.

5.4 use

A few aliases help with my "used-by, i-use" confusion:

$ ga use
alias i_use='fun_uses'
alias use_me='fuse'
$

Here's a self-refernential usage:

$ i_use fuse
fuse
needir
spaceit
$
$ use_me fuse
clf         set -- $( args_uniq $(fuse ${1:-clf} | field 1 ));
fapi            set -- $( args_uniq $(fuse $1 | field 1 | sed 4q ));
fapi            _fun_show fuse $1 | _trim_hash
fnuse       declare -f $1 $( fuse $1|field 1 )
fun_create          fuse eval | grep '()' | sed 's/ *()/ ()/; s/ *\$/$/' | awk '$4 ~ /()/'
fun_maker           set | fuse eval | grep ' () ' | field 1
fun_useme           fuse ${1:-ff} | awk '
fuse        local tmp=$( needir $HOME/tmp )/fuse.tmp;
fuse        local awk=$( needir $HOME/tmp )/fuse.awk;
fuse_lib                fuse $1 | sed "s/^/$1   /"
fuse_lib            foreach _fuse_one $( functions $1 ) | tee fuse.out | field 1 | uniq -c | awk '$1 < 2 { print $2 }';
fuse_lib            wc fuse.out 1>&2
isclf       set -- $( args_uniq $(fuse ${1:-$(myname )} | field 1));
sfuse       fuse $1
$

Worth noticing the difference in output format. e.g. use_me, namely fuse, shows the context where the function is used, "how am I invoked", and i_use, namely fun_uses, only shows the list of called functions.

6 Maintenance

An alias is created on the command line. For example:

$ alias llrt='ls -lrt'

The current aliases are saved to the alias file with the sava alias:

alias sava='(alias; echo alias) > ~/.alias.rc; alias'

An alias may be removed by manually editing the .alias.rc file. More natural might be the feature:

$ unalias some-alias-name;  sava

This example shows the both the value of the function over the alias, and the point of the alias: KISS

7 References

Author: Marty McGowan

Created: 2018-06-09 Sat 14:54

Emacs 24.4.1 (Org mode 8.2.10)

Validate