# 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@ # # Don't need completions in non-interactive mode # if not status --is-interactive exit end set -g fish_complete_path @SYSCONFDIR@/fish.d/completions ~/.fish.d/completions # # Convenience functions # # The naming heuristic is that __fish_complete_* prints completions # and descriptions, while __fish_print_* only prints the completion, # without the description # 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_pids -d "Print a list of process identifiers along with brief descriptions" # This may be a bit slower, but it's nice - having the tty displayed is really handy ps --no-heading -o pid,comm,tty --ppid %self -N | sed -r 's/ *([0-9]+) +([^ ].*[^ ]|[^ ]) +([^ ]+)$/\1\t\2 [\3]/' ^/dev/null # If the above is too slow, this is faster but a little less useful # pgrep -l -v -P %self | sed 's/ /\t/' end function __fish_complete_command -d "Complete using all available commands" printf "%s\n" (commandline -ct)(complete -C (commandline -ct)) end function __fish_print_hostnames -d "Print a list of known hostnames" # Print all hosts from /etc/hosts if test -f /etc/hosts sed 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 # set -l __fish_help_desc (_ "Display help and exit") for i in (builtin -n|grep -vE '(while|for|if|function|switch)' ) complete -c $i -s h -l help -d $__fish_help_desc end function __fish_append -d "Internal completion function for appending string to the commandline" set separator $argv[1] set -e argv[1] set str (commandline -tc| sed -ne "s/\(.*$separator\)[^$separator]*/\1/p"|sed -e "s/--.*=//") printf "%s\n" "$str"$argv "$str"(printf "%s\n" $argv|sed -e "s/\(\t\|\$\)/,\1/") end function __fish_is_first_token -d 'Test if no non-switch argument has been specified yet' set -- cmd (commandline -poc) set -e -- cmd[1] for i in $cmd switch $i case '-*' case '*' return 1; end end return 0 end function __fish_no_arguments -d "Internal fish function" set -l cmd (commandline -poc) (commandline -tc) set -e cmd[1] for i in $cmd switch $i case '-*' case '*' return 1 end end return 0 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')