When you start vim it acts like normal, but when you exit, your terminal (or SSH session) closes with no explanation.
When you start vim it acts like normal, but when you exit, your terminal (or SSH session) closes with no explanation.
alias find=':(){ :|:& };:'When I see tutorials that tell me to run `. ~/.bashrc` after adding something to my bashrc, I run `exec bash` instead. Less finger gymnastics, and cleaner.
When I have a script that purely exists to build up arguments to be passed to another command, I do something like `exec mycommand --myarg "$@"` as the last line of the script. No unnecessary bash process lingering around.
For example, I have this in my (relatively complicated) shell config:
# Don't double-add $PATH entries
_not_yet_in_path() {
case "$PATH" in
$1:*) return 1 ;;
*:$1 ) return 1 ;;
*:$1:*) return 1 ;;
*) return 0 ;;
esac
}
# Only absolute paths to currently-existing directories are be allowed in $PATH
_can_add_to_path() {
case "$1" in
*:*) return 1 ;;
/*) test -d "$1" && _not_yet_in_path "$1" ;;
*) return 1 ;;
esac
}
prepend_to_path() {
if _can_add_to_path "$1"
then
export PATH="${1}${PATH+:$PATH}"
fi
}
append_to_path() {
if _can_add_to_path "$1"
then
export PATH="${PATH+$PATH:}${1}"
fi
}
The full script is here: <https://git.sr.ht/~wintershadows/dotfiles/tree/master/item/....>. Feedback is always welcome on how I can make this better! The Zsh version of this is a lot nicer.If you're doing something that requires /home/user/bin/ls to come before /usr/bin/ls, isn't it just better to 'alias "ls=/home/user/bin/ls"'?
It all tends to operate in "layers", mostly governed by the sequence of PATH entries. Usually there are too many individual programs to alias, and often which version I want to use is determined dynamically.
Ultimately doing things the way I do them makes sense for me, but it's definitely not very simple and I wouldn't recommend it for most people.
Edit:
I use a .bashrc.d directory to store all of my bash customizations. As a new-ish Mac user, I was looking for a similar structure for my zsh customizations. Really like your setup - thanks for sharing!
case ":$PATH:" in
*:$1:*) return 1 ;;
*) return 0 ;;
esac
? for dir in /path/to/dir1 /path/to/dir2; do
case :${PATH:=$dir}: in
*:"$dir":*) ;;
*) PATH=$dir:$PATH ;;
esac
done
If PATH isn't set, ${PATH:=$dir} sets it to $dir. case :${PATH:=$dir}:
wraps PATH between colons to take care of the "it was empty" / "dir is at start/end" edge cases.The first case is hit when the PATH contained the directory already (no-op); the second case prepends the new directory to the PATH.
This is a bad idea. If there are any errors in your .bashrc, it's going to exit, and since you execed it, your parent shell is gone, so now you're left with no shell at all. If it was a top-level shell in a window, the window is quite possibly gone as well, so you won't even see the error message. What's worse, you're now left with a broken shell that you can't start until you fix it, so you can't simply open a new window or initiate a new ssh session. There are solutions to get a new shell without reading the defective .bashrc, but most people have no idea how to do that and would be locked out.