4 ms·
If 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 u
by fiddlerwoaroof 3y ago
If 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?
- fiddlerwoaroof 3y agoNo, this is global: I use direnv too. It’s more like “roll your own oh-my-zsh”
- brezelgoring 3y agoNobody asked but I'd like to chime in with my method. I have a lot of aliases, for example to start my QEMU VM with my development stuff in it, I make an alias for 'qemu-system-x86_64 [...]' with all the switches and devices and files required, called 'startvm'. I have another that takes me to my current project's folder and pulls the repo. And a third that creates a new folder called 'newproject', creates a small set of folders and empty files with specific names, and finally makes a git repo in it. I am a serial abandoner of projects so I use this more often than I care to admit. It's not pretty, but functional; and since I always copy my dotfiles when I change computers, I've kept these small helpers with me for a while now.