2006-10-19 19:50:23 +08:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
2007-04-23 02:49:56 +08:00
|
|
|
#
|
|
|
|
# Set default field separators
|
|
|
|
#
|
|
|
|
|
|
|
|
set -g IFS \n\ \t
|
|
|
|
|
2014-02-21 02:26:57 +08:00
|
|
|
#
|
|
|
|
# Create the default command_not_found handler
|
|
|
|
#
|
|
|
|
function __fish_default_command_not_found_handler
|
2016-02-27 12:22:59 +08:00
|
|
|
echo "fish: Unknown command '$argv'" >&2
|
2014-02-21 02:26:57 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Hook up the default as the principal command_not_found handler
|
2015-12-29 22:41:00 +08:00
|
|
|
# in case we are not interactive
|
2014-02-21 02:26:57 +08:00
|
|
|
#
|
2015-12-29 22:41:00 +08:00
|
|
|
status -i; or function __fish_command_not_found_handler --on-event fish_command_not_found
|
2016-02-27 12:22:59 +08:00
|
|
|
__fish_default_command_not_found_handler $argv
|
2014-02-21 02:26:57 +08:00
|
|
|
end
|
|
|
|
|
2006-10-19 19:50:23 +08:00
|
|
|
#
|
|
|
|
# Set default search paths for completions and shellscript functions
|
|
|
|
# unless they already exist
|
|
|
|
#
|
|
|
|
|
|
|
|
set -l configdir ~/.config
|
2007-10-28 17:08:40 +08:00
|
|
|
|
2006-10-19 19:50:23 +08:00
|
|
|
if set -q XDG_CONFIG_HOME
|
|
|
|
set configdir $XDG_CONFIG_HOME
|
|
|
|
end
|
|
|
|
|
2014-09-29 19:39:36 +08:00
|
|
|
set -l userdatadir ~/.local/share
|
|
|
|
|
|
|
|
if set -q XDG_DATA_HOME
|
|
|
|
set userdatadir $XDG_DATA_HOME
|
|
|
|
end
|
|
|
|
|
2012-07-09 06:20:39 +08:00
|
|
|
# __fish_datadir, __fish_sysconfdir, __fish_help_dir, __fish_bin_dir
|
|
|
|
# are expected to have been set up by read_init from fish.cpp
|
2006-10-19 19:50:23 +08:00
|
|
|
|
2007-10-28 17:08:40 +08:00
|
|
|
# Set up function and completion paths. Make sure that the fish
|
|
|
|
# default functions/completions are included in the respective path.
|
|
|
|
|
2010-09-18 10:18:26 +08:00
|
|
|
if not set -q fish_function_path
|
2016-02-27 12:22:59 +08:00
|
|
|
set fish_function_path $configdir/fish/functions $__fish_sysconfdir/functions $__fish_datadir/vendor_functions.d $__fish_datadir/functions
|
2006-10-19 19:50:23 +08:00
|
|
|
end
|
|
|
|
|
2012-07-09 06:20:39 +08:00
|
|
|
if not contains $__fish_datadir/functions $fish_function_path
|
2016-02-27 12:22:59 +08:00
|
|
|
set fish_function_path $fish_function_path $__fish_datadir/functions
|
2007-10-28 17:10:42 +08:00
|
|
|
end
|
|
|
|
|
2010-09-18 10:18:26 +08:00
|
|
|
if not set -q fish_complete_path
|
2016-02-27 12:22:59 +08:00
|
|
|
set fish_complete_path $configdir/fish/completions $__fish_sysconfdir/completions $__fish_datadir/vendor_completions.d $__fish_datadir/completions $userdatadir/fish/generated_completions
|
2006-10-19 19:50:23 +08:00
|
|
|
end
|
|
|
|
|
2012-07-09 06:20:39 +08:00
|
|
|
if not contains $__fish_datadir/completions $fish_complete_path
|
2016-02-27 12:22:59 +08:00
|
|
|
set fish_complete_path $fish_complete_path $__fish_datadir/completions
|
2007-10-28 17:10:42 +08:00
|
|
|
end
|
|
|
|
|
2007-10-28 17:08:40 +08:00
|
|
|
#
|
2006-10-19 19:50:23 +08:00
|
|
|
# This is a Solaris-specific test to modify the PATH so that
|
2007-10-28 17:08:40 +08:00
|
|
|
# Posix-conformant tools are used by default. It is separate from the
|
|
|
|
# other PATH code because this directory needs to be prepended, not
|
|
|
|
# appended, since it contains POSIX-compliant replacements for various
|
|
|
|
# system utilities.
|
|
|
|
#
|
2006-10-19 19:50:23 +08:00
|
|
|
|
|
|
|
if test -d /usr/xpg4/bin
|
|
|
|
if not contains /usr/xpg4/bin $PATH
|
2010-09-18 10:18:26 +08:00
|
|
|
set PATH /usr/xpg4/bin $PATH
|
2006-10-19 19:50:23 +08:00
|
|
|
end
|
2010-09-18 10:18:26 +08:00
|
|
|
end
|
2006-10-19 19:50:23 +08:00
|
|
|
|
2013-02-23 06:01:17 +08:00
|
|
|
# OS X-ism: Load the path files out of /etc/paths and /etc/paths.d/*
|
2013-08-26 04:25:24 +08:00
|
|
|
set -g __fish_tmp_path $PATH
|
2013-02-23 06:01:17 +08:00
|
|
|
function __fish_load_path_helper_paths
|
2013-08-26 05:00:56 +08:00
|
|
|
# We want to rearrange the path to reflect this order. Delete that path component if it exists and then prepend it.
|
|
|
|
# Since we are prepending but want to preserve the order of the input file, we reverse the array, append, and then reverse it again
|
2016-02-27 12:22:59 +08:00
|
|
|
set __fish_tmp_path $__fish_tmp_path[-1..1]
|
|
|
|
while read -l new_path_comp
|
|
|
|
set -l where (contains -i $new_path_comp $__fish_tmp_path)
|
|
|
|
and set -e __fish_tmp_path[$where]
|
|
|
|
set __fish_tmp_path $new_path_comp $__fish_tmp_path
|
|
|
|
end
|
|
|
|
set __fish_tmp_path $__fish_tmp_path[-1..1]
|
2013-02-23 06:01:17 +08:00
|
|
|
end
|
2013-08-26 04:25:24 +08:00
|
|
|
test -r /etc/paths ; and __fish_load_path_helper_paths < /etc/paths
|
2013-02-23 06:01:17 +08:00
|
|
|
for pathfile in /etc/paths.d/* ; __fish_load_path_helper_paths < $pathfile ; end
|
2013-08-26 04:25:24 +08:00
|
|
|
set -xg PATH $__fish_tmp_path
|
|
|
|
set -e __fish_tmp_path
|
2013-02-23 06:01:17 +08:00
|
|
|
functions -e __fish_load_path_helper_paths
|
|
|
|
|
|
|
|
|
2013-08-26 04:25:24 +08:00
|
|
|
# Add a handler for when fish_user_path changes, so we can apply the same changes to PATH
|
|
|
|
# Invoke it immediately to apply the current value of fish_user_path
|
|
|
|
function __fish_reconstruct_path -d "Update PATH when fish_user_paths changes" --on-variable fish_user_paths
|
|
|
|
set -l local_path $PATH
|
|
|
|
set -l x
|
|
|
|
for x in $__fish_added_user_paths
|
|
|
|
set -l idx (contains --index $x $local_path)
|
|
|
|
and set -e local_path[$idx]
|
|
|
|
end
|
|
|
|
|
|
|
|
set -e __fish_added_user_paths
|
|
|
|
for x in $fish_user_paths[-1..1]
|
2013-12-11 01:52:04 +08:00
|
|
|
if set -l idx (contains --index $x $local_path)
|
|
|
|
set -e local_path[$idx]
|
|
|
|
else
|
2013-08-26 04:25:24 +08:00
|
|
|
set -g __fish_added_user_paths $__fish_added_user_paths $x
|
|
|
|
end
|
2013-12-11 01:52:04 +08:00
|
|
|
set local_path $x $local_path
|
2013-08-26 04:25:24 +08:00
|
|
|
end
|
|
|
|
set -xg PATH $local_path
|
|
|
|
end
|
|
|
|
__fish_reconstruct_path
|
|
|
|
|
2007-08-20 00:42:30 +08:00
|
|
|
#
|
2007-04-24 05:10:26 +08:00
|
|
|
# Launch debugger on SIGTRAP
|
2007-08-20 00:42:30 +08:00
|
|
|
#
|
2013-02-20 09:48:51 +08:00
|
|
|
function fish_sigtrap_handler --on-signal TRAP --no-scope-shadowing --description "Signal handler for the TRAP signal. Launches a debug prompt."
|
2007-04-24 05:10:26 +08:00
|
|
|
breakpoint
|
|
|
|
end
|
2006-10-19 19:50:23 +08:00
|
|
|
|
2007-08-20 00:42:30 +08:00
|
|
|
#
|
|
|
|
# Whenever a prompt is displayed, make sure that interactive
|
|
|
|
# mode-specific initializations have been performed.
|
2007-10-28 17:11:17 +08:00
|
|
|
# This handler removes itself after it is first called.
|
2007-08-20 00:42:30 +08:00
|
|
|
#
|
|
|
|
function __fish_on_interactive --on-event fish_prompt
|
|
|
|
__fish_config_interactive
|
2007-10-28 17:11:17 +08:00
|
|
|
functions -e __fish_on_interactive
|
2006-10-19 19:50:23 +08:00
|
|
|
end
|
2007-08-20 00:42:30 +08:00
|
|
|
|
2013-08-14 23:43:09 +08:00
|
|
|
# "." command for compatibility with old fish versions.
|
2013-08-18 08:04:16 +08:00
|
|
|
function . --description 'Evaluate contents of file (deprecated, see "source")' --no-scope-shadowing
|
2013-08-14 23:43:09 +08:00
|
|
|
if begin
|
|
|
|
test (count $argv) -eq 0
|
|
|
|
# Uses tty directly, as isatty depends on "."
|
|
|
|
and tty 0>&0 >/dev/null
|
|
|
|
end
|
|
|
|
echo "source: '.' command is deprecated, and doesn't work with STDIN anymore. Did you mean 'source' or './'?" >&2
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
source $argv
|
|
|
|
end
|
|
|
|
end
|
2015-10-21 05:21:57 +08:00
|
|
|
|
|
|
|
# As last part of initialization, source the conf directories
|
|
|
|
# Implement precedence (User > Admin > Vendors > Fish) by basically doing "basename"
|
|
|
|
set -l sourcelist
|
|
|
|
for file in $configdir/fish/conf.d/* $__fish_sysconfdir/conf.d/* $__fish_datadir/vendor_conf.d/*
|
|
|
|
set -l basename (string replace -r '^.*/' '' -- $file)
|
|
|
|
contains -- $basename $sourcelist; and continue
|
|
|
|
set sourcelist $sourcelist $basename
|
|
|
|
# Also skip non-files or unreadable files
|
|
|
|
# This allows one to use e.g. symlinks to /dev/null to "mask" something (like in systemd)
|
|
|
|
[ -f $file -a -r $file ]; and source $file
|
|
|
|
end
|