aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/fish.in
blob: df3433bc4d70c63761113bb09674e8a0381d814a (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#
# Main file for fish command completions. This file contains various
# common helper functions for the command completions. All actual
# completions are located in the completions subdirectory.
#
# @configure_input@

# This is a Solaris-specific test to modify the PATH so that
# Posix-conformant tools are used by default.

if test -d /usr/bin/xpg4
	if not echo $PATH | grep /usr/bin/xpg4 >/dev/null
		set PATH /usr/bin/xpg4 $PATH 
	end
end   

# Assign a temporary value here for performance reasons. The real
# value should be set in /etc/fish.

set -g fish_function_path @datadir@/fish/functions/
set __fish_help_dir @docdir@


#
# Make sure there are no invalid entries in the PATH
#

if status --is-interactive
	set -l erase_idx
	for idx in (seq (count $PATH))
		set i $PATH[$idx]
		if not test -d $i
			set erase_idx $erase_idx $idx
			printf (_ '%s: Warning: The directory %s has been removed from your PATH because it does not exist\n') fish $i
		end
	end

	if count $erase_idx >/dev/null
		set -e PATH[(echo $erase_idx)]
	end
end

#
# Add a few common directories to path, if they exists. Note that pure
# console programs like makedep sometimes live in /usr/X11R6/bin, so we
# want this even for text-only terminals.
#

set -l path_list /bin /usr/bin /usr/X11R6/bin @prefix@/bin @optbindirs@

# Root should also have the sbin directories in the path
if test "$USER" = root
	set path_list $path_list /sbin /usr/sbin /usr/local/sbin
end

# Make a regular expression that matches any component in the PATH. A
# trailing slash is ok. The sed call is to remove the last '\|'.  
set -l tmp (printf "%s" \^$PATH'/?$|')
set -l path_regexp \((echo $tmp | sed -e "s/.\$//")\)

for i in (printf "%s\n" $path_list|grep -E -v $path_regexp)
	if test -d $i
		set PATH $PATH $i
	end
end

#
# Don't need completions in non-interactive mode
#

if not status --is-interactive
	exit
end

#
# Convenience functions
#
# The naming heuristic is that __fish_complete_* prints completions
# and descriptions, while __fish_print_* only prints the completions
# and no descriptions
#

function __fish_complete_users -d "Print a list of local users, with the real user name as a description"
	cat /etc/passwd | sed -e "s/^\([^:]*\):[^:]*:[^:]*:[^:]*:\([^:]*\):.*/\1\t\2/"
end

function __fish_complete_groups -d "Print a list of local groups, with group members as the description"
	cat /etc/group | sed -e "s/^\([^:]*\):[^:]*:[^:]*:\(.*\)/\1\tMembers: \2/"
end

function __fish_complete_command -d "Complete using all available commands"
	printf "%s\n" (commandline -ct)(complete -C (commandline -ct))
end

function __fish_print_interfaces -d "Print a list of known network interfaces"
	netstat -i -n -a | awk 'NR>2'|awk '{print $1}'
end

function __fish_print_addresses -d "Print a list of known network addresses"
	/sbin/ifconfig |grep 'inet addr'|cut -d : -f 2|cut -d ' ' -f 1
end

function __fish_print_users -d "Print a list of local users"
	cat /etc/passwd | cut -d : -f 1
end

#
# Completions for the shell and it's builtin commands and functions
#

for i in (builtin -n|grep -E -v '(while|for|if|function|switch)' )
	complete -c $i -s h -l help -d "Display help and exit"
end


#
# Completions for SysV startup scripts
#

complete -x -p "/etc/init.d/*" -a start\t(_ 'Start service')
complete -x -p "/etc/init.d/*" -a stop\t(_ 'Stop service')
complete -x -p "/etc/init.d/*" -a status\t(_ 'Print service status')
complete -x -p "/etc/init.d/*" -a restart\t(_ 'Stop and then start service')
complete -x -p "/etc/init.d/*" -a reload\t(_ 'Reload service configuration')