Re:$!134 can be a nice bash foot shooter if you accidentally...
by kevincox on Tuesday December 28, 2021 @08:23AM
(#29713517)
I have a similar system but take advantage of prefix-search rather than Ctrl+r
For commands that I reuse semi-frequently I set an environment variable so that I can easily find them with prefix searching. So for example I sometimes pin IPFS paths to Infura so I have this command in my history. I can then type pin=<Up> and recall that command (until it drops off the end of my shell history).
pin= r curl -fiXPOST "https://ipfs.infura.io:5001/api/v0/pin/add?recursive=true&arg=$(c)"
Re:$!134 can be a nice bash foot shooter if you accidentally...
by boffinAudio on Tuesday December 28, 2021 @08:30AM
(#29713582)
Useful, but dangerous! I would have to check if there is already an environment variable in use before I did that ..
Re:$!134 can be a nice bash foot shooter if you accidentally...
by kevincox on Tuesday December 28, 2021 @08:32AM
(#29713596)
I know this command doesn't depend on a lowercase `pin` variable so there is no danger. Note that this doesn't change the variable in the shell, just the executed command.
Re:$!134 can be a nice bash foot shooter if you accidentally...
by boffinAudio on Tuesday December 28, 2021 @08:47AM
(#29713698)
Yeah, its the 'knowing beforehand' part that makes this dangerous for me. ;)
Cute trick though, will work it into my workflow and see how it feels.
Re:$!134 can be a nice bash foot shooter if you accidentally...
by kevincox on Tuesday December 28, 2021 @08:50AM
(#29713735)
IDK, environment variables get set all of the time, I rarely worry about them breaking programs. Their job is kinda to live in the background and be passed through programs so it doesn't feel like much danger. Especially when I use lowercase and almost all programs use uppercase.
But I guess everyone has a different risk level and what feels near-zero to me is meaningful to someone else.
By COMMENTING your commands:
$ grep -i myname /etc/passwd # passgrep
.. ..
$ Ctrl-R "passgr"
It is so rewarding to do some intense bash work with liberal command line comments and then come back a few weeks later, "history | grep \#", and see my work notes - along with the relevant commands - available.
I used to write '~/bin' scripts for special stuff, including comments in the .sh source itself - but now it just makes more sense to wang a comment at the end of the complex/interesting commands and then just grep for the comment later ..