7 ms·
I maintain a file with commands that I don't use often (ex: increase volume with ffmpeg, add a border to an image with convert, etc). I even have a shortcut tha
by asicsp 3y ago
I maintain a file with commands that I don't use often (ex: increase volume with ffmpeg, add a border to an image with convert, etc). I even have a shortcut that'll add the last executed command to this file and another shortcut to search from this file.
- redlohr 3y agoOh, that's a great idea. I have a doc that I maintain by hand, either via ">>" or editing directly. Time to go and make a shortcut. Do you do any annotation to help with the search?
- asicsp 3y agoUsually no annotations, as I typically search by command name. But sometimes I edit the file to add comments if there are many examples for the same command.
- mmcdermott 3y agoA large Justfile (https://just.systems/ https://just.systems/) of random recipes might be a way to make it both executable and searchable (at least on zsh, you can get an autocomplete list of completions from the command line).
- cole-k 3y agoCan you think of a single CLI tool that would let me commit a past incantation to a file and retrieve it later? Especially one that syncs well across devices. The best I can think of is Atuin (https://github.com/atuinsh/atuin https://github.com/atuinsh/atuin) but I wasn't super interested in using it - I kind of want something more lightweight.
- mmc 3y agoI've been using a little set of bash funcs I called `hs` for this for a few years: https://github.com/mikemccracken/hs https://github.com/mikemccracken/hs your snippets are stored in a git repo that you can sync around how you like.
- kenoh 3y agoPretty much the same, though I usually just keep the file open in a side terminal. I want to use stuff like cheat.sh (ex. curl cheat.sh/grep) but I never remember.
- fiddlerwoaroof 3y agoIf you’re already putting them in a file, you might as well put them in a shell script on $PATH: at a certain point I started writing shell scripts and little utilities for relatively infrequently used commands and other tasks (e.g. clone this repo from GitHub to a well-known location and cd to it)
- eschneider 3y agoKeeping a ~/bin directory with all your personal shell shortcut scripts has been my go-to for years. I tend to make a lot of project-specific shortcut scripts for anything that I want to remember/becomes a common task.
- ustad 3y agoWait, how do you “cd to it” from within the script? Doesn’t exiting the script take you back to where you were?
- justin_oaks 3y agoYou're right that you often can't modify your current environment by invoking a shell script. That's because it's executed in a sub-shell. For cases where you need to modify your current environment (setting environment variables, changing directories, etc), you need to run the script using the "source" built-in. That will execute the script in the current shell rather than a sub-shell. So instead of ./some-script.sh you'd run source some-script.sh or use the dot (".") shorthand . some-script.sh In cases where I need to source a script, I generally create an alias or a shell function for it. Otherwise I may forget to source it.
- fiddlerwoaroof 3y agoFor this I use shell functions in my .zshrc and I wrote a loader to source a bunch of files in a .zsh.d directory.
- tripleo1 3y agoRolled your own direnv?
- cole-k 3y agoIf you don't mind, it would be awesome to see your cheatsheet. I think this would be a great thing for people to share - like their dotfiles. But maybe they already do and I don't pay much attention to it because I'm lazy - like their dotfiles.
- hiAndrewQuinn 3y agoI like `fzf`'s default override of Ctrl+R backwards search for this purpose, along with the fish shell's really good built in autocompletion. I've been thinking about updating the GIFs in my fzf tutorial to show off fish, but I think I'd rather leave them with ish just so I don't dilute the pedagogical message.
- xenodium 3y agoOh, specially ffmpeg and imagemagick! I have a handful of incantations saved over time. Just today I saved a new one for trimming borders on video screenshots https://xenodium.com/trimming-video-screenshots https://xenodium.com/trimming-video-screenshots to https://github.com/xenodium/dwim-shell-command/blob/main/dwim-shell-commands.el https://github.com/xenodium/dwim-shell-command/blob/main/dwi... (that’s my cheat sheet). I wrote an Emacs package that works fairly well for saving commands but also making them reusable from its file manager without the need to tweak input or output file paths https://github.com/xenodium/dwim-shell-command https://github.com/xenodium/dwim-shell-command While Emacs isn’t everyone’s cup of tea, I think the same concept can be applied elsewhere. Right click on file(s) from macOS Finder or Windows Explorer and apply any of those saved commands. Edit: More examples… - Stitching multiple images: https://xenodium.com/joining-images-from-the-comfort-of-dired https://xenodium.com/joining-images-from-the-comfort-of-dire... - Batch apply on file selections: https://xenodium.com/emacs-dwim-shell-command https://xenodium.com/emacs-dwim-shell-command