Add some fzf aliases to change directory.
This commit is contained in:
		
							parent
							
								
									bb2ef487d7
								
							
						
					
					
						commit
						fc5941eacb
					
				
							
								
								
									
										60
									
								
								zshrc
								
								
								
								
							
							
						
						
									
										60
									
								
								zshrc
								
								
								
								
							|  | @ -694,6 +694,66 @@ function translate() | |||
|   wget -U "Mozilla/5.0" -qO - "http://translate.google.com/translate_a/t?client=t&text=${1}&sl=${2}&tl=${3}" | sed 's/\[\[\[\"//' | cut -d \" -f 1 | ||||
| } | ||||
| 
 | ||||
| ## fzf | ||||
| 
 | ||||
| # fd - cd to selected directory (exclude hidden directories | ||||
| fd() { | ||||
| 	local dir | ||||
| 	dir=$(find ${1:-.} -path '*/\.*' -prune \ | ||||
| 		-o -type d -print 2> /dev/null | fzf +m) && | ||||
| 		cd "$dir" | ||||
| } | ||||
| 
 | ||||
| # fdh - hidden directories only | ||||
| fdh() { | ||||
| 	local dir | ||||
| 	dir=$(find ${1:-.} -type d 2> /dev/null | fzf +m) && cd "$dir" | ||||
| } | ||||
| 
 | ||||
| # fda - all directories | ||||
| 
 | ||||
| # fdr - cd to selected parent directory | ||||
| fdr() { | ||||
| 	local declare dirs=() | ||||
| 	get_parent_dirs() { | ||||
| 		if [[ -d "${1}" ]]; then dirs+=("$1"); else return; fi | ||||
| 		if [[ "${1}" == '/' ]]; then | ||||
| 			for _dir in "${dirs[@]}"; do echo $_dir; done | ||||
| 		else | ||||
| 			get_parent_dirs $(dirname "$1") | ||||
| 		fi | ||||
| 	} | ||||
| 	local DIR=$(get_parent_dirs $(realpath "${1:-$PWD}") | fzf-tmux --tac) | ||||
| 	cd "$DIR" | ||||
| } | ||||
| 
 | ||||
| # fdf - cd into the directory of the selected file | ||||
| fdf() { | ||||
| 	local file | ||||
| 	local dir | ||||
| 	file=$(fzf +m -q "$1") && dir=$(dirname "$file") && cd "$dir" | ||||
| } | ||||
| 
 | ||||
| # cf - fuzzy cd from anywhere | ||||
| # ex: cf word1 word2 ... (even part of a file name) | ||||
| # zsh autoload function | ||||
| cf() { | ||||
| 	local file | ||||
| 
 | ||||
| 	file="$(locate -Ai -0 $@ | grep -z -vE '~$' | fzf --read0 -0 -1)" | ||||
| 
 | ||||
| 	if [[ -n $file ]] | ||||
| 	then | ||||
| 		if [[ -d $file ]] | ||||
| 		then | ||||
| 			cd -- $file | ||||
| 		else | ||||
| 			cd -- ${file:h} | ||||
| 		fi | ||||
| 	fi | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| ################################################ | ||||
| # 2. Prompt et définition des touches basiques # | ||||
| ################################################ | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue