Skip to main content
replaced http://superuser.com/ with https://superuser.com/
Source Link

From the bash(1) man page:

ALIASES Aliases allow a string to be substituted for a word when it is used as the first word of a simple command. [...] 

So bash aliases do not have this capability, nor does bash have a trivial pre-exec capability (but see heresee here for a hack though).

As a partial workaround you may be able to use a completion function, here's a minimal starting point:

function _comp_cd() { local cur=${COMP_WORDS[COMP_CWORD]} # the current token [[ $cur =~ \.\.\. ]] && { cur=${cur/.../..\/..} COMPREPLY=( $cur ) return } COMPREPLY=() # let default kick in } complete -o bashdefault -o default -F _comp_cd cd 

Now when you hit tab on a cd command and the word under the cursor contains "...", each will be replaced with "../..". Completion suffers from a slight problem too though (excluding its complexity) which you can probably guess from the above, you need to specify it on a command by command basis.

The bash-completion package uses a default completion handler, with on-the-fly loading of completion functions to deal with this. If you're feeling adventurous you should be able to modify its internal function _filedir() function which is used for general file/directory expansion so as to include a similar substitution "...".

(All of which reminds of the NetWare shell, which made "..." Just Work.)

From the bash(1) man page:

ALIASES Aliases allow a string to be substituted for a word when it is used as the first word of a simple command. [...] 

So bash aliases do not have this capability, nor does bash have a trivial pre-exec capability (but see here for a hack though).

As a partial workaround you may be able to use a completion function, here's a minimal starting point:

function _comp_cd() { local cur=${COMP_WORDS[COMP_CWORD]} # the current token [[ $cur =~ \.\.\. ]] && { cur=${cur/.../..\/..} COMPREPLY=( $cur ) return } COMPREPLY=() # let default kick in } complete -o bashdefault -o default -F _comp_cd cd 

Now when you hit tab on a cd command and the word under the cursor contains "...", each will be replaced with "../..". Completion suffers from a slight problem too though (excluding its complexity) which you can probably guess from the above, you need to specify it on a command by command basis.

The bash-completion package uses a default completion handler, with on-the-fly loading of completion functions to deal with this. If you're feeling adventurous you should be able to modify its internal function _filedir() function which is used for general file/directory expansion so as to include a similar substitution "...".

(All of which reminds of the NetWare shell, which made "..." Just Work.)

From the bash(1) man page:

ALIASES Aliases allow a string to be substituted for a word when it is used as the first word of a simple command. [...] 

So bash aliases do not have this capability, nor does bash have a trivial pre-exec capability (but see here for a hack though).

As a partial workaround you may be able to use a completion function, here's a minimal starting point:

function _comp_cd() { local cur=${COMP_WORDS[COMP_CWORD]} # the current token [[ $cur =~ \.\.\. ]] && { cur=${cur/.../..\/..} COMPREPLY=( $cur ) return } COMPREPLY=() # let default kick in } complete -o bashdefault -o default -F _comp_cd cd 

Now when you hit tab on a cd command and the word under the cursor contains "...", each will be replaced with "../..". Completion suffers from a slight problem too though (excluding its complexity) which you can probably guess from the above, you need to specify it on a command by command basis.

The bash-completion package uses a default completion handler, with on-the-fly loading of completion functions to deal with this. If you're feeling adventurous you should be able to modify its internal function _filedir() function which is used for general file/directory expansion so as to include a similar substitution "...".

(All of which reminds of the NetWare shell, which made "..." Just Work.)

Source Link
mr.spuratic
  • 10.4k
  • 29
  • 46

From the bash(1) man page:

ALIASES Aliases allow a string to be substituted for a word when it is used as the first word of a simple command. [...] 

So bash aliases do not have this capability, nor does bash have a trivial pre-exec capability (but see here for a hack though).

As a partial workaround you may be able to use a completion function, here's a minimal starting point:

function _comp_cd() { local cur=${COMP_WORDS[COMP_CWORD]} # the current token [[ $cur =~ \.\.\. ]] && { cur=${cur/.../..\/..} COMPREPLY=( $cur ) return } COMPREPLY=() # let default kick in } complete -o bashdefault -o default -F _comp_cd cd 

Now when you hit tab on a cd command and the word under the cursor contains "...", each will be replaced with "../..". Completion suffers from a slight problem too though (excluding its complexity) which you can probably guess from the above, you need to specify it on a command by command basis.

The bash-completion package uses a default completion handler, with on-the-fly loading of completion functions to deal with this. If you're feeling adventurous you should be able to modify its internal function _filedir() function which is used for general file/directory expansion so as to include a similar substitution "...".

(All of which reminds of the NetWare shell, which made "..." Just Work.)