Start all of your commands with a comma (2009)
rhodesmill.org
rhodesmill.org
I already have a PATH order. What would be nice is if typing say `sc` gave me the first `sc` program, but typing `,sc` gave me the one after that.
This would generalize, so if I were stuck with cough several pythons I could call them with `python`, `,python`, `,,python` and so forth.
This would be a shell-level patch but surely not an impossible one.
Ironically, the one person whose workflow this would clobber is the one who wrote this blog post!
Who has the wrong solution now?
A good shell like fish could provide the full path name as a hint for any use of ,
Because otherwise why not just do what I assume everyone else does, and put ~/bin before everything else on your PATH?
For example, let’s say I have a script that improves upon the systemctl command, and I want to use it all the time and not type a bunch of characters to invoke it. I might call it “sc”, forgetting that I also use the spreadsheet calculator sometimes.
If I always prefix, then “,sc” is my shortcut, and “sc” is the spreadsheet calculator.
The system programs can potentially rely on each other, invoking each other in a way that relies on PATH searching, and not set PATH to a sane value when they are invoked. Your utility can accidentally shadow something and break the program whicc relies on it.
In other words, setting PATH to point to ~/bin first breaks unhygienic programs which blindly inherit PATH --- which is pretty much all non-setuid programs in a Unix-like system!
Setting PATH to point to your ~/bin last, on the other and, potentially breaks your programs when they call each other (in a way that relies on path searching), and are shadowed by new system programs. A fix for that is to to put ~/bin last, and ensure that all your programs refer to each other in a way that doesn't rely on PATH. E.g. prog is invoked as $bob_utils/prog.
Not a problem I've ever had, but I guess I like the solution if it's one you do often.
Thanks for confirming.
For instance, my programs might be in /home/kaz/bin. Suppose I create a one-letter variable:
k=/home/kaz/bin
Then /home/kaz/bin/foo can be run as $k/foo
Bash will complete on this. Firstly, $k[Tab] will add the missing slash to make $k/. Then if Tab is hit twice, the completions under /home/kaz/bin are shown.Since k contains an absolute path, it does not rely on PATH searching.
The programs under $k/ can refer to each other using the $k/ notation, without relying on PATH.
The comma notation relies on PATH. When the ,foo script wants to invoke the ,bar script and just calls it ,bar args ... that relies on PATH containing the directory in which ,bar lives.
For interactive use, I'd use PATH anyway: put /home/kaz/bin at the end. Then if the system shadows one of my programs prog, I can just use ~/utils/prog or $k/prog to detour around the clashing system program. My programs themselves don't rely on PATH for calling each other, so they are immune to the shadowing, and since I added the new PATH element at the end, I haven't perpetrated any shadowing that would break system programs.
hash -d b=/home/me/bin
Then you call foo as: ~b/foo
I have an array of these defined to my most used directories.I wonder (having never really grokked the latter) if it's productive to think of this as akin to a leader key in vim ….
Erm, nope:
$ dnf repoquery -l $(dnf repoquery -f /usr/bin/\*) | grep ^/usr/bin | wc -l
34989Agree with the commit message; I've probably spent way too much time the past decade firing up a python prompt or using an online epoch converter to do this.
date -d @$1 +%Y-%m-%dThis. I always forget the names of all these useful tools that I only use now and then.
Examples:
cat -> cat_uni_my (personal implementation of standard cat)
grep -> grep_uni_my (personal implementation of standard grep)
Say you have an alias that overrides `ls`. When you want to run original ls, you run `command ls`.
Wonder if you have /usr/bin/command - well gotta try it! :)
/bin/lsIs there an alternate mechanism for invoking a shell's built-ins externally? Obviously for state-changing operations such as 'cd' that's of limited use.
$SHELL -c '<commands>'
Comes to mind. Though likely bypassing initialisations might be useful.Assume I have commands my_cat, my_grep, my_sort, my_send, and I want to use them in a pipe
with_prefix my_ | cat file | grep phrase | sort | send | end_with | cat
The last cat would be the system one.
I don't think it's possible with bash?
No, pipes don't work like that. The closest I can think of is something like `(PATH=~/bin; cat file | grep phrase | sort | send) | cat`, where the custom commands don't have a prefix.
( source with_my_prefix.sh
cat file | grep phrase | sort | send | end_with | cat
)Been doing it for years with a jj prefix instead, it is just under my index finger on the home row :-)
jjdoc jjs jjtree
on Ubuntu 18.04https://www.apple.com/uk/shop/product/MLA22B/A/magic-keyboar...
Instead of prefixing my commands, I just search for a command in a manpage repo, cht.sh [0], and with my package manager (`dnf provides` for the DNF package manager). If nothing shows up, I'm probably safe. The process is easy to automate.
The author's solution does seem much better; I just use my approach instead because I don't like the feeling of typing a leading comma :). I might switch to using a leading char sometime.
[0]: https://git.sr.ht/~seirdy/dotfiles/tree/master/Executables/s...
[1]: https://git.sr.ht/~seirdy/dotfiles/tree/master/startup.sh#L1...
▷ echo 'echo "this is a -test"' > ~/bin/-test
▷ chmod +x ~/bin/-test
▷ -test
this is a -testNo, this is my laptop - /usr/bin is the place for that. No, this is a simple server - /usr/bin is the place for that.
Perhaps I'm missing something after 23 odd years of using Unix systems including this Arch laptop.
https://blog.w1r3.net/2018/01/06/rob-landley-about-usr-split...