https://tuckerchapman.com/2018/06/16/how-to-use-the-vim-lead...
Start all of your commands with a comma (2009)
101–110 of 130 posts
Re: Start all of your commands with a comma (2009)
#102Clever trick. Too bad there's no good way to namespace commands. It would be interesting if you could have, for instance: $ mkdir -p /tmp/bin/my $ printf '%s\n%s\n' '#!/bin/sh' 'echo hello' > /tmp/bin/my/hello $ chmod 755 /tmp/bin/my/hello $ PATH="/tmp/bin:$PATH" $ my/hello hello
$ my hello
It would mean tools such as git, microk8s and aws wouldn’t have to implement that “look up first argument, check whether it’s a command I know, and if so, run it” on their own, and would have slightly simpler auto complete configs.It also could mean launching fewer processes (for the case where ‘my’ is a script or executable that looks up the location of ‘hello’ and launches it)
Re: Start all of your commands with a comma (2009)
#103Re: Start all of your commands with a comma (2009)
#104Re: Start all of your commands with a comma (2009)
#105Re: Start all of your commands with a comma (2009)
#106 my() {
script_name="$1"
script_path="$HOME/.local/bin/my/$script_name"
shift
$script_path "$@"
}
So you have your namespace ? Of course that mean you must put all script in .local/bin, not anywhere in the PATH, and some more work is needed to figure out completion.But it seems less weird than the comma.
-- EDIT --
With completion:
export MY_SCRIPS_DIR="$HOME/.local/bin/my"
_my_completions() {
if [ "${#COMP_WORDS[@]}" != "2" ]; then
return
fi
COMPREPLY=($(compgen -W "$(echo $(find "$MY_SCRIPS_DIR" -printf '%P\n' ))"))
}
my() {
script_name="$1"
script_path="$MY_SCRIPS_DIR/$script_name"
shift
$script_path "$@"
}
complete -F _my_completions my
-- EDIT 2 --After testing both, the comma win. Kiss, more flexible.
Re: Start all of your commands with a comma (2009)
#107Clever trick. Too bad there's no good way to namespace commands. It would be interesting if you could have, for instance: $ mkdir -p /tmp/bin/my $ printf '%s\n%s\n' '#!/bin/sh' 'echo hello' > /tmp/bin/my/hello $ chmod 755 /tmp/bin/my/hello $ PATH="/tmp/bin:$PATH" $ my/hello hello
Re: Start all of your commands with a comma (2009)
#108A bit more fiddly perhaps, but future proof.
Re: Start all of your commands with a comma (2009)
#109clever idea, but does it need such a long post to describe?