Earlier quoted context omitted.
Typing Esc then . does the trick too.
Only in emacs editing mode. Real programmers use set -o vi
How to navigate directories faster with Bash (2015)
161–170 of 179 posts
Re: How to navigate directories faster with Bash (2015)
#162Re: How to navigate directories faster with Bash (2015)
#163For me once I moved to zsh and added `oh my zsh` it really became so much easier. I like the autocomplete, the fact that when cd-ing a known path you can just type the first leter of each directory with slashes, showing the git branch in working dir. Its the little things.
Re: How to navigate directories faster with Bash (2015)
#164For me once I moved to zsh and added `oh my zsh` it really became so much easier. I like the autocomplete, the fact that when cd-ing a known path you can just type the first leter of each directory with slashes, showing the git branch in working dir. Its the little things.
'oh my zsh' is fun, but they really throw the kitchen sink in there. I had to get rid of it because terminal startup speed and doing anything in large folders was incredibly slow If all the components of 'oh my zsh' were compiled into the shell and shared data structures, I bet it would be as fast as bash and only limited by IO
Re: How to navigate directories faster with Bash (2015)
#165Earlier quoted context omitted.
https://www.gnu.org/software/bash/manual/html_node/Bindable-... is a must read.
Thanks, I discovered C-o thanks to you (even though I have gone through the bash manual several times). No, more having to press C-r multiple times just to get sequential group of commands from history.
Also keep in mind that most interactive command-line tools are built upon readline and can understand all those bindings (think python REPL, mysql/psql...)
Re: How to navigate directories faster with Bash (2015)
#166The most important tool I found for switching directories is called "z". You just partially type a previously visited directory's name and it takes you there. It also keeps track of your history to rank candidates for popularity. https://github.com/rupa/z/ It's basically CDPATH on stereoids and doesn't require preconfiguration like CDPATH.
Similar is https://lib.rs/crates/zoxide if you're a fan of rust based solutions :) .
Re: How to navigate directories faster with Bash (2015)
#167Those bunch of dots aliases are a bit ridiculous. What are you gonna do, sit and count dots?
# When called as `argu string`, prints the closest ancestor directory which
# contains "string". If none is found, or "string" is empty, the current
# working directory is printed. This function is useful if you need to specify
# a file as an argument, but the relative path to it involves moving several
# directories up from the current directory. For example, instead of doing:
# $ pwd
# /this/is/a/very/long/directory/path/for/demonstration/purposes/
# $ ls ../../../../another/directory/something.log
# You could do:
# $ ls `argu dir`/another/directory/something.log
argu() {
if [[ "$1" == "" ]]; then
echo "`pwd`/"
return
fi
echo "`pwd | sed "s/^\(.*"$1"[^/]*\)\/.*$/\1/g"`/"
}
# When called as `cdu string`, changes directories into the closest ancestor
# directory of the current directory which contains "string". If none is found,
# or "string" is empty, no changes are made to the current directory.
cdu() {
cd `argu $1`
}
I also put the following in ~/.zsh/completion/_cdu so I can get tab-completion of the portions of the path: #compdef cdu
_cdu_parents=$(pwd | tr '/' ' ')
_arguments "1:parents:($_cdu_parents)"
Or bash (in ~/.bash/completion/cdu): # bash completion for cdu
_cdu()
{
local cur prev split=false
COMPREPLY=()
_get_comp_words_by_ref -n : cur prev
_dirs=$( pwd | tr '/' ' ' )
COMPREPLY=( $( compgen -W "$_dirs" -- "$cur" ) )
}
complete -F _cdu cdu
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=shRe: How to navigate directories faster with Bash (2015)
#168I 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,…
cdn is a good idea. I'm going to steal it, and change it to ncd, so that all i have to do to add that 'n' is C-a to the begin of line.
Re: How to navigate directories faster with Bash (2015)
#169Earlier quoted context omitted.
Thanks, I discovered C-o thanks to you (even though I have gone through the bash manual several times). No, more having to press C-r multiple times just to get sequential group of commands from history.
Yes I was also impressed when I found out about this one. However I use it far less frequently than ALT-. . ALT-# is also useful in the frequent cases where I am constructing a complicated commmand but I have to run another command before the current one. Also keep in mind that most interactive command-line tools are built upon readline and can understand all those bindings (think python REPL, mysql/psql...)
Haha of course. I use it so frequently I can't imagine how anyone uses their shell without it.
>can understand all those bindings
I knew that but just being reminded helped me realize that C-o is probably going to be useful in the REPL as well. Thanks.
Re: How to navigate directories faster with Bash (2015)
#170Earlier quoted context omitted.
I don't think this is documented anywhere that I've found, but git checkout - checks out the previous branch you were on, similar to cd -
Big fan of git-aliasing this to `git back`. I actually use it a ton and that small amount of extra chars plus the "-" makes a pretty decent difference for me.
I usually do `g c -` but I guess `g back` wouldn't be bad.