How to navigate directories faster with Bash (2015)
151–160 of 179 posts
Re: How to navigate directories faster with Bash (2015)
#152Another one: cdof () { cd "$(dirname $1)" } as in 'Change into Directory Of" Changes into the directory of a file. This is useful when you're doing complicated commands with long path names, but realize it would be easier if you were to cd into that directory. Use in combination with . Especially useful if the filename component is long: $ pwd => ~/ $ ls -l path/to/whatever/deep/somewhere/2021-04-22-filewithverylongn…
bit longer, but if given a file, change to its directory function cd() { if [[ ${#} -eq 0 ]]; then builtin cd return fi if [[ -f ${1} ]]; then builtin cd $(dirname ${1}) else builtin cd ${1} fi }
function gothere {
cd $(dirname -z `find -iname $1`)
}Re: How to navigate directories faster with Bash (2015)
#153I 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.
n!!
(!! repeats the previous command).
Re: How to navigate directories faster with Bash (2015)
#154Re: How to navigate directories faster with Bash (2015)
#155Here 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)
#156I 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…
I have an "mkcd" function in my startup files: mkcd() { mkdir -vp "$1" && cd "$1"; }
alias tcd='a=`date +%s`;mkdir "$a" && cd "$a"'Re: How to navigate directories faster with Bash (2015)
#157 # fuzzy search any command
f(){
ROOT_DIR="."
[ -n "$2" ] && ROOT_DIR="$2"
FZF_OUT=`fd . -H --color=always "$ROOT_DIR" --exclude "Software/"| fzf --query="$3"`
[ -n "$FZF_OUT" ] && "$1" "$FZF_OUT"
}
in my case Software/ is a directory with lots of files I don't need so I exclude it from my searches. I also like using ranger, it has very nice bookmarking and launcher features.Re: How to navigate directories faster with Bash (2015)
#158Or 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/
It get critiqued a lot, but I'd suggest others try it out before dismissing it and see if it works for them.
Re: How to navigate directories faster with Bash (2015)
#159The author missed to mention one of my favorite tricks to change back in to the last visited directory: cd - Hint: Change into directory called '-' can be done by cd ./- I also use the mkcd alias / function: mkcd() { mkdir -p "$@" && cd !$; } This allows creating multiple dirs and cd into the first one. mkcd test1 test2 test3
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 -
Re: How to navigate directories faster with Bash (2015)
#160The 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.