The tilde is not an alias, it's part of bash's shell expansion (just like *.txt
or $((1 + 2))
).
Bash tilde expansion supports the following tilde-prefixes:
~ The value of $HOME
~/foo $HOME/foo
~fred/foo The subdirectory foo of the home directory of the user fred
~+/foo $PWD/foo
~-/foo ${OLDPWD-'~-'}/foo
~N The string that would be displayed by `dirs +N'
~+N The string that would be displayed by `dirs +N'
~-N The string that would be displayed by `dirs -N'
dirs
uses the directory stack. You can use pushd
to add a directory to it.
To answer your specific question about ~~
, yes, it is possible to map a directory to it. Just create a user called ~
and set /mnt/photon/work/foo_project/
as its home directory:
sudo useradd '~'
sudo sed -i 's#:/home/~:[^:]*$#:/mnt/photon/work/foo_project:/bin/false#' /etc/passwd
Of course, a much "saner" approach is just defining a shell variable that points to your directory in your ~/.bashrc
with the command
foo=/mnt/photon/work/foo_project
which can be accessed via $foo
, as usual.
n=/mnt/photon/work/foo_project
and thencp foo ~n/bar
. (Note for the OP: Also limited to zsh).@
or_
), which isn't possible in bash, while~~
certainly is (hacky, but possible). Also, it doesn't answer how this remapping is done.