bash - Alias Substitution in Fish Shell -


question: there fish equivalent of bash's alias substitution or what's recommended best practice keep code clean , dry?

background: there's useful feature of aliases in bash called alias substitution. it's mentioned briefly in man page:

alias [-p] [name[=value] ...]     ...     trailing space in value causes next word checked alias substitution when alias expanded.     ... 

the power of functionality may conveyed example. consider many users define grep alias. here's mine:

# extended regex, skip binaries, devices, sockets, & dirs, colored, & line # -buffered. use non- canonical alias instead of grep_options may wreck # poorly written scripts alias g='grep -eid skip -d skip --color=auto --line-buffered' 

similarly, many of same users define alias xargs. here's mine without alias substitution:

alias x='xargs -rd\\n' # \n delimited, don't run on empty in 

and finally, here's how might want use doesn't work:

$ find|x g foo xargs: g: no such file or directory 

this command fails because x expanded xargs , can't find executable called g. there number of workarounds think awful. however, adding trailing space, shell perform alias substitution on our behalf , command work intended:

alias x='xargs -rd\\n ' # \n delimited, don't run on empty in, + expansion #                    ^-- space expanding subsequent alias 

please keep in mind just example, not actual use case.

update 2015-05-06

i never found fishism solution felt alternative worth comment. took approach of creating shell scripts in ~/bin. downsides are:

  • the shell configuration multiple files.
  • the interpreter loses inspection of otherwise simple aliases , functions.

however, felt upsides pretty huge:

  • the scripts may written in language.
  • the scripts independent of shell choice. trying new shells extremely painless. it's been joy have single prompt script doesn't have rewritten or maintained in multiple languages.

this isn't fish based solution -- suspect fish answer going it's not possible.

you create aliases .fish or .sh scripts , symlink them /usr/local/bin -- give equivalent behaviour.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -