I'm looking for a way to change the default directory of cd, and I'm wondering if this is possible. I tried adding
alias "cd=cd ~/Documents/Github"
Here's a simpler alternative using an alias:
alias cd='HOME=~/Documents/Github cd'
$HOME, it does so ONLY for the
cdcommand, so should be safe(*).
If you place this in
~/.bashrc, you should get the desired behavior.
Note that, by default, this alias will NOT be in effect in scripts (non-interactive shells), as alias expansion is by default disabled there (use
shopt -s expand_aliases to explicitly enable).
(*) @chepner points out one restriction: with the alias in place you won't be able to do
HOME=/somewhere/else cd, i.e., you won't be able to redefine (override)
$HOME again, ad-hoc. As he further states, though, it's hard to imagine why anyone would want to do that.