Start all of your commands with a comma (2009)
rhodesmill.org
rhodesmill.org
The alias itself looks a bit weird in that to pass arguments to an aliased command you need to use a function (in Bash at least AFACIT) but it all works fine.
As aliases aren't sourced when other scripts are running, I'm sure my scripts/commands ain't ever going to clash with anything.
I've been doing that since years.
It also works fine to add "wrappers" to existing commands: for example to add additional input sanitization catching common mistakes I'm making when calling some commands.
function ,foo() { printf "Fooo\n"; }
,foo
actually works! (at least in my bash 5.0.17 shell)No you don't:
$ alias say=echo
$ say beep
beep
You do need to do something special the other way around (if you wrap a command in a function it needs to explicitly pass the arguments on). alias watch='watch '
Specifically, if an alias ends with a space, it will cause the subsequent arg to be expanded as well. For example, try running: alias beep=echo
watch beep hello # This will fail
alias watch='watch '
watch beep hello # Now it works!
[1]: https://news.ycombinator.com/item?id=31830879.foo1,.foo2, .foo3, and so on.
env > "$(date +s).env-snapshot"
(And use it again slightly more awkwardly as <$file | xargs -I@ echo '"@"' | tr '\n' ' ' | xargs -I@ env @ cmd
or something more convenient to `cmd`.) <$file xargs ...If it is any consolation, I can't make any sense of this.
$ <xyz.txt wc -l
8
$ <xyz.txt | wc -l
0docker gives you this (but only as part of a whole ecosystem, which for various reasons you might not want to hitch your horse to).
``` cp () { rsync -avhW --progress --inplace ${@} } ```
If I ever need to use the `cp` binary, I execute `=cp`, which evaluates to `/bin/cp`.
Because of some common layout of keyboards the \ and ] are near each other, or in reach of left and right pinkies I can type \]\ before the name of the tools. This means I don't even have add a dir to the path.
I am sure this violates someone sensibilities but it has saved time over the years as a consultant when I had to deal with a wonky machine and owner did not want permanent install of diagnostic tools.
Post-vista, c:\programdata\tools
Set yourself a %TOOLS% environment variable.
$ 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 $ touch foo::bar
$ chmod +x foo::bar
$ ./foo::bar && echo $?
It's an empty file so it does nothing, but most shells' lexers should be smart enough to not try and lex '::'.Edit: Forgot to mention, this also works with bash functions and aliases. I'm not sure if POSIX sh will allow it. You can also do things like this (again, not sure I'd recommend it):
$ alias +x='chmod +x'This is not a secure way of using /tmp.
edit: Or I would fix it, but I guess I can't edit it. Oh well.
$ export $MY = /tmp/my
$ $MY/hello
helloNeither do home directories.
I made a little tool that dispatches hierarchical commands in a slightly nicer way, with intelligent autocomplete with command descriptions: https://github.com/ianthehenry/sd
my hello
I.e. only my needs to be in the global namespace and all other commands are resolved by my itself. $ 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)
That allows me to type `soriloco`, punch ctrl+r and be prompted with `some ridiculously long command` (if, of course, I've run it before).
Combined with infinite history this trick has saved me a bunch of typing and even proper remembering. :P
function .routes() {
if [[ $# -eq 0 ]]; then
.rails routes
else
.rails routes | grep $@
fi
}
where .rails is another alias (for running bundle exec rails ...). I can then run ".routes webhook" and see all routes containing "webhook".Last but not least, I automated the whole thing with bash-ctx (https://github.com/gregnavis/bash-ctx).
rsync becomes myrsync mount becomes mymount ssh becoms myssh
No collision and the naming convention empathise that it is indeed used be MYself.
I don't particularly want to have to type 30-character names all the time without tab completion, but I'm not going to worry about an eight character command vs. a four character one.
Obviously this doesn't apply if you are dyslexic or disabled in some way or something.
I have a script that creates new ~/bin scripts that checks for collisions locally (functions, builtins, and executables) and in linux distros.
For example, I have a ~/bin/up script on every box and platform to install updates. So far so good on collisions.
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.
Though it doesn’t mention using ~/bin. I use that but don’t add it to my path, so I have to explicitly call my scripts.
The comment history suggests it isn’t a bit though.
A bit more fiddly perhaps, but future proof.
Also in the article itself, the author argues against any prefix char that requires using the shift key.
For example I have ‘_f’ aliased to a fuzzy find command that will launch vim on the selected files, and a different one for launching sql clients to various servers etc.
As a prefix, commas work great!
https://tuckerchapman.com/2018/06/16/how-to-use-the-vim-lead...
I’m gonna start them with `å` just to be a little different.
I'm genuinely interested to know whether you read longform text at all.
* I just use "tweet" as a unit of measure, like "the size of two elephants". I do not advocate the use of twitter.
hash -d e=/bin/echo
~e hello world
https://ato.pxeger.com/run?1=m724qjhjwYKlpSVpuhY3lTMSizMUdFM...I believe you have made my point quite well once it's understood you are here referring to none other than prefixing script names with a comma. Any words wasted on anything other than the subject is a waste of words, in your comment's case, both ad hominem and straw man fallacies.