I have created lots of directories and I would to make my life lazy and to auto cd
into the directory that I made with the option of -g
with the result of mkdir -g foo
The terminal would be like this:
User:/$ mkdir -g foo
User:/foo/$
I have looked at this page but with no success.
Is there a one-liner that allows me to create a directory and move into it at the same time?
I have tried in my .bash_profile
with this command, but it just overrides the command entirely. (and realizing that it is an infinite loop later)
mkdir() {
if "$1" -eq "-g"
mkdir "$2"
cd "$2"
else
## do the regular code
fi
}
The other thing is that I don't want to make more aliases because I will eventually forget all of the aliases that I have.
So not I don't want this:
the command entirely. (and realizing that it is an infinite loop later)
mkcd() {
if "$1" -eq "-g"
mkdir "$2"
cd "$2"
else
## do the regular code
fi
}
I know that I most likely don't have the option thingy right, please correct me on that, but any help would be awesome!
$(which mkdir)
to invoke the systemmkdir
. I strongly recommend making an alias with a different name though. – DepressedDaniel Feb 26 '17 at 23:25source
other people's code. I would really advise to make a different alias for your command, e.g.mkcdir
. – undercat Feb 26 '17 at 23:26