File: __fish_complete_cd.fish

package info (click to toggle)
fish 1.23.0-5
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 6,416 kB
  • ctags: 2,503
  • sloc: ansic: 35,998; sh: 2,818; makefile: 566
file content (43 lines) | stat: -rw-r--r-- 847 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function __fish_complete_cd -d "Completions for the cd command"

	#
	# We can't simply use __fish_complete_directories because of the CDPATH
	#

	set -l wd $PWD
	set -l owd $OLDPWD

	# Check if CDPATH is set

	set -l mycdpath

	if test -z $CDPATH[1]
		set mycdpath .
	else
		set mycdpath $CDPATH
	end

	
	if echo (commandline -ct)|sgrep '^/\|^\./\|^\.\./' >/dev/null
		# This is an absolute search path
		eval printf '\%s\\tDirectory\\n' (commandline -ct)\*/
	else
		# This is a relative search path
		# Iterate over every directory in CDPATH 
		# and check for possible completions

		for i in $mycdpath
			# Move to the initial directory first, 
			# in case the CDPATH directory is relative

			builtin cd $wd
			builtin cd $i

			eval printf '"%s\tDirectory in "'$i'"\n"' (commandline -ct)\*/
		end
	end

	builtin cd $wd
	set OLDPWD $owd
end