Earlier quoted context omitted.
For this exact use case I defined the following many years ago in my bash profile: # create a new directory and enter it function mkd() { mkdir -p "$@" && cd "$_"; } And use it like: mkd foo
Beware that using "$@" there might not be what you want, as it passes space-separated arguments to mkdir. What does: "mkd foo bar" do? It creates both directories, and cd's into "bar". Might be worth checking that only one argument has been passed, or use "$*" which instead would treat all arguments as one parameter, and "mkd foo bar" would create a "foo bar" directory instead (and cd to it) YMMV.
How to navigate directories faster with Bash (2015)
111–120 of 179 posts
Re: How to navigate directories faster with Bash (2015)
#112 shopt -s cdable_vars
p=/some/path/you/cd/to/a/bunch
cd pRe: How to navigate directories faster with Bash (2015)
#113I use `z` as a less manual way to search common directories instead of changing $CDPATH. It's based on 'frecency'. https://github.com/rupa/z
Re: How to navigate directories faster with Bash (2015)
#114Here is one additional bookmark solution [1]: export CDPATH=.:~/.marks/ function mark { ln -sr "$(pwd)" ~/.marks/"$1" } mark @name # create a bookmark cd @name # jump to bookmark cd @ # list bookmarks cd @n # auto-complete cd @name/ # can access sub-directories within bookmarks Works best when bookmarks are prefixed by "@" or other special symbol. Additional advantage is that you can use the same function `cd` to nav…
Re: How to navigate directories faster with Bash (2015)
#115I use `z` as a less manual way to search common directories instead of changing $CDPATH. It's based on 'frecency'. https://github.com/rupa/z
zsh, oh-my-zsh and z are the must haves that I add to any new environment immediately. Z and similar tools is such an elegant solution to directory navigation.
I love Z but I cannot believe there isn't something better yet?
One thing I'd love is something that helps navigating the current git project easier.
Re: How to navigate directories faster with Bash (2015)
#116I do the following [1]: - I define "cdn" to be what others call "mkcd", as then if I have a command line "cd foo" and it tells me that foo doesn't exist, I can just add the 'n' to the previous entry. I also overload "cdn" so that when not given any argument, it goes into the newest subdirectory in the current directory. - "u", "uu", "uuu", "uuuu", "uuuuu" for going "up" that many levels, and unlike the aliases in OP,…
Re: How to navigate directories faster with Bash (2015)
#117Here is one additional bookmark solution [1]: export CDPATH=.:~/.marks/ function mark { ln -sr "$(pwd)" ~/.marks/"$1" } mark @name # create a bookmark cd @name # jump to bookmark cd @ # list bookmarks cd @n # auto-complete cd @name/ # can access sub-directories within bookmarks Works best when bookmarks are prefixed by "@" or other special symbol. Additional advantage is that you can use the same function `cd` to nav…
Pretty sure this would change into the symlinks, not the linked directories. I.e. the $PWD would be under `~/.marks/`.
alias cd="cd -P"Re: How to navigate directories faster with Bash (2015)
#118Or you just use a shell like fish that already comes with a lot of useful defaults. No need to customize everything by yourself, just use what other smart people already created. https://fishshell.com/
Every once and then I decide to use and love the fish shell, and I commit to using it exclusively for a few days. My first session always starts with 40 minutes trying to disable all stupid colors. I don't like my terminal to look like a kitsch Christmas tree! Then, I feel frustrated with "jumps" of the interface when editing multi-line command lines; inevitably leading me to quit fish and go back to bash. I'm obviously not smart enough to appreciate the defaults that these smart people have created.
Re: How to navigate directories faster with Bash (2015)
#119I upvoted for this alone: Another neat short hand is !$ which is an alias for the last argument of the previous command. This can be handy if one creates a new directory and wants to change into it without typing the the directory again. So commands would be mkdir -p make/new/directory cd !$ You've no idea how many years I've been thinking "This is Linux fer gawd's sake. Surely there must be some easy way to make a n…
In zsh, you use -> % take which makes the dir and cd's into it.
Re: How to navigate directories faster with Bash (2015)
#120Or you just use a shell like fish that already comes with a lot of useful defaults. No need to customize everything by yourself, just use what other smart people already created. https://fishshell.com/
> No need to customize everything by yourself, just use what other smart people already created. Every once and then I decide to use and love the fish shell, and I commit to using it exclusively for a few days. My first session always starts with 40 minutes trying to disable all stupid colors. I don't like my terminal to look like a kitsch Christmas tree! Then, I feel frustrated with "jumps" of the interface when edi…