2006-10-19 11:50:23 +00: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-22 18:49:56 +00:00
|
|
|
#
|
|
|
|
# Set default field separators
|
|
|
|
#
|
|
|
|
set -g IFS \n\ \t
|
2017-07-02 03:45:30 +00:00
|
|
|
set -qg __fish_added_user_paths
|
|
|
|
or set -g __fish_added_user_paths
|
2007-04-22 18:49:56 +00:00
|
|
|
|
2014-02-20 18:26:57 +00:00
|
|
|
#
|
|
|
|
# Create the default command_not_found handler
|
|
|
|
#
|
|
|
|
function __fish_default_command_not_found_handler
|
2019-01-29 03:35:17 +00:00
|
|
|
printf "fish: Unknown command: %s\n" (string escape -- $argv[1]) >&2
|
2014-02-20 18:26:57 +00:00
|
|
|
end
|
|
|
|
|
2016-04-16 11:00:14 +00:00
|
|
|
if status --is-interactive
|
2019-02-11 05:47:10 +00:00
|
|
|
# Enable truecolor/24-bit support for select terminals
|
|
|
|
# Ignore Screen and emacs' ansi-term as they swallow the sequences, rendering the text white.
|
|
|
|
if not set -q STY
|
|
|
|
and not string match -q -- 'eterm*' $TERM
|
|
|
|
and begin
|
|
|
|
set -q KONSOLE_PROFILE_NAME # KDE's konsole
|
|
|
|
or string match -q -- "*:*" $ITERM_SESSION_ID # Supporting versions of iTerm2 will include a colon here
|
|
|
|
or string match -q -- "st-*" $TERM # suckless' st
|
|
|
|
or test -n "$VTE_VERSION" -a "$VTE_VERSION" -ge 3600 # Should be all gtk3-vte-based terms after version 3.6.0.0
|
|
|
|
or test "$COLORTERM" = truecolor -o "$COLORTERM" = 24bit # slang expects this
|
2016-12-04 04:36:47 +00:00
|
|
|
end
|
2019-02-11 05:47:10 +00:00
|
|
|
# Only set it if it isn't to allow override by setting to 0
|
|
|
|
set -q fish_term24bit
|
|
|
|
or set -g fish_term24bit 1
|
2016-12-04 04:36:47 +00:00
|
|
|
end
|
2016-04-16 11:00:14 +00:00
|
|
|
else
|
2016-12-04 04:36:47 +00:00
|
|
|
# Hook up the default as the principal command_not_found handler
|
|
|
|
# in case we are not interactive
|
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
|
|
|
__fish_default_command_not_found_handler $argv
|
|
|
|
end
|
2014-02-20 18:26:57 +00:00
|
|
|
end
|
|
|
|
|
2006-10-19 11:50:23 +00:00
|
|
|
#
|
|
|
|
# Set default search paths for completions and shellscript functions
|
|
|
|
# unless they already exist
|
|
|
|
#
|
|
|
|
|
2018-03-12 13:34:20 +00:00
|
|
|
# __fish_data_dir, __fish_sysconf_dir, __fish_help_dir, __fish_bin_dir
|
2012-07-08 22:20:39 +00:00
|
|
|
# are expected to have been set up by read_init from fish.cpp
|
2006-10-19 11:50:23 +00:00
|
|
|
|
2016-04-04 06:33:35 +00:00
|
|
|
# Grab extra directories (as specified by the build process, usually for
|
|
|
|
# third-party packages to ship completions &c.
|
|
|
|
set -l __extra_completionsdir
|
|
|
|
set -l __extra_functionsdir
|
2016-04-05 14:22:12 +00:00
|
|
|
set -l __extra_confdir
|
2018-03-12 13:34:20 +00:00
|
|
|
if test -f $__fish_data_dir/__fish_build_paths.fish
|
|
|
|
source $__fish_data_dir/__fish_build_paths.fish
|
2016-04-04 06:33:35 +00:00
|
|
|
end
|
|
|
|
|
2007-10-28 09:08:40 +00:00
|
|
|
# Set up function and completion paths. Make sure that the fish
|
|
|
|
# default functions/completions are included in the respective path.
|
|
|
|
|
2010-09-18 02:18:26 +00:00
|
|
|
if not set -q fish_function_path
|
2018-10-21 13:42:25 +00:00
|
|
|
set fish_function_path $__fish_config_dir/functions $__fish_sysconf_dir/functions $__extra_functionsdir $__fish_data_dir/functions
|
2019-02-11 17:08:28 +00:00
|
|
|
else if not contains -- $__fish_data_dir/functions $fish_function_path
|
|
|
|
set -a fish_function_path $__fish_data_dir/functions
|
2007-10-28 09:10:42 +00:00
|
|
|
end
|
|
|
|
|
2010-09-18 02:18:26 +00:00
|
|
|
if not set -q fish_complete_path
|
2018-12-15 04:09:29 +00:00
|
|
|
set fish_complete_path $__fish_config_dir/completions $__fish_sysconf_dir/completions $__extra_completionsdir $__fish_data_dir/completions $__fish_user_data_dir/generated_completions
|
2019-02-11 17:08:28 +00:00
|
|
|
else if not contains -- $__fish_data_dir/completions $fish_complete_path
|
|
|
|
set -a fish_complete_path $__fish_data_dir/completions
|
2007-10-28 09:10:42 +00:00
|
|
|
end
|
|
|
|
|
2018-05-03 10:42:09 +00:00
|
|
|
# This cannot be in an autoload-file because `:.fish` is an invalid filename on windows.
|
2019-02-11 17:08:28 +00:00
|
|
|
function : -d "no-op function"
|
|
|
|
# for compatibility with sh, bash, and others.
|
2018-05-03 10:42:09 +00:00
|
|
|
# Often used to insert a comment into a chain of commands without having
|
2019-02-11 17:08:28 +00:00
|
|
|
# it eat up the remainder of the line, handy in Makefiles.
|
2018-05-03 10:42:09 +00:00
|
|
|
end
|
2018-03-15 23:18:57 +00:00
|
|
|
|
2007-10-28 09:08:40 +00:00
|
|
|
#
|
2006-10-19 11:50:23 +00:00
|
|
|
# This is a Solaris-specific test to modify the PATH so that
|
2007-10-28 09:08:40 +00: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 11:50:23 +00:00
|
|
|
|
|
|
|
if test -d /usr/xpg4/bin
|
2019-02-11 17:08:28 +00:00
|
|
|
not contains -- /usr/xpg4/bin $PATH
|
|
|
|
and set PATH /usr/xpg4/bin $PATH
|
2010-09-18 02:18:26 +00:00
|
|
|
end
|
2006-10-19 11:50:23 +00:00
|
|
|
|
2013-08-25 20:25:24 +00:00
|
|
|
# Add a handler for when fish_user_path changes, so we can apply the same changes to PATH
|
|
|
|
function __fish_reconstruct_path -d "Update PATH when fish_user_paths changes" --on-variable fish_user_paths
|
2016-12-04 04:36:47 +00:00
|
|
|
set -l local_path $PATH
|
2017-07-02 03:45:30 +00:00
|
|
|
|
2016-12-04 04:36:47 +00:00
|
|
|
for x in $__fish_added_user_paths
|
|
|
|
set -l idx (contains --index -- $x $local_path)
|
|
|
|
and set -e local_path[$idx]
|
|
|
|
end
|
|
|
|
|
2017-07-02 03:45:30 +00:00
|
|
|
set -g __fish_added_user_paths
|
|
|
|
if set -q fish_user_paths
|
2019-02-13 11:35:15 +00:00
|
|
|
# Explicitly split on ":" because $fish_user_paths might not be a path variable,
|
|
|
|
# but $PATH definitely is.
|
|
|
|
for x in (string split ":" -- $fish_user_paths[-1..1])
|
2017-07-02 03:45:30 +00:00
|
|
|
if set -l idx (contains --index -- $x $local_path)
|
|
|
|
set -e local_path[$idx]
|
|
|
|
else
|
2019-02-11 17:08:28 +00:00
|
|
|
set -ga __fish_added_user_paths $x
|
2017-07-02 03:45:30 +00:00
|
|
|
end
|
2019-02-11 17:08:28 +00:00
|
|
|
set -p local_path $x
|
2016-12-04 04:36:47 +00:00
|
|
|
end
|
|
|
|
end
|
2017-07-02 20:41:07 +00:00
|
|
|
|
2016-12-04 04:36:47 +00:00
|
|
|
set -xg PATH $local_path
|
2013-08-25 20:25:24 +00:00
|
|
|
end
|
2017-07-02 03:45:30 +00:00
|
|
|
|
2007-08-19 16:42:30 +00:00
|
|
|
#
|
2007-04-23 21:10:26 +00:00
|
|
|
# Launch debugger on SIGTRAP
|
2007-08-19 16:42:30 +00:00
|
|
|
#
|
2013-02-20 01:48:51 +00:00
|
|
|
function fish_sigtrap_handler --on-signal TRAP --no-scope-shadowing --description "Signal handler for the TRAP signal. Launches a debug prompt."
|
2016-12-04 04:36:47 +00:00
|
|
|
breakpoint
|
2007-04-23 21:10:26 +00:00
|
|
|
end
|
2006-10-19 11:50:23 +00:00
|
|
|
|
2007-08-19 16:42:30 +00:00
|
|
|
#
|
|
|
|
# Whenever a prompt is displayed, make sure that interactive
|
|
|
|
# mode-specific initializations have been performed.
|
2007-10-28 09:11:17 +00:00
|
|
|
# This handler removes itself after it is first called.
|
2007-08-19 16:42:30 +00:00
|
|
|
#
|
|
|
|
function __fish_on_interactive --on-event fish_prompt
|
2016-12-04 04:36:47 +00:00
|
|
|
__fish_config_interactive
|
|
|
|
functions -e __fish_on_interactive
|
2006-10-19 11:50:23 +00:00
|
|
|
end
|
2007-08-19 16:42:30 +00:00
|
|
|
|
2016-07-10 16:34:27 +00:00
|
|
|
# Set the locale if it isn't explicitly set. Allowing the lack of locale env vars to imply the
|
|
|
|
# C/POSIX locale causes too many problems. Do this before reading the snippets because they might be
|
|
|
|
# in UTF-8 (with non-ASCII characters).
|
|
|
|
__fish_set_locale
|
|
|
|
|
2019-02-11 07:18:38 +00:00
|
|
|
# "." alias for source; deprecated
|
|
|
|
function . -d 'Evaluate a file (deprecated, use "source")' --no-scope-shadowing --wraps source
|
|
|
|
if [ (count $argv) -eq 0 ] && isatty 0
|
|
|
|
echo "source: using source via '.' is deprecated, and stdin doesn't work."\n"Did you mean 'source' or './'?" >&2
|
2018-05-09 14:46:17 +00:00
|
|
|
return 1
|
|
|
|
else
|
|
|
|
source $argv
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-02 03:45:30 +00:00
|
|
|
# Upgrade pre-existing abbreviations from the old "key=value" to the new "key value" syntax.
|
|
|
|
# This needs to be in share/config.fish because __fish_config_interactive is called after sourcing
|
|
|
|
# config.fish, which might contain abbr calls.
|
2016-03-01 19:22:21 +00:00
|
|
|
if not set -q __fish_init_2_3_0
|
2017-07-03 04:16:48 +00:00
|
|
|
if set -q fish_user_abbreviations
|
|
|
|
set -l fab
|
|
|
|
for abbr in $fish_user_abbreviations
|
2019-02-11 17:08:28 +00:00
|
|
|
set -a fab (string replace -r '^([^ =]+)=(.*)$' '$1 $2' -- $abbr)
|
2017-07-03 04:16:48 +00:00
|
|
|
end
|
|
|
|
set fish_user_abbreviations $fab
|
2016-12-04 04:36:47 +00:00
|
|
|
end
|
|
|
|
set -U __fish_init_2_3_0
|
2016-03-01 19:22:21 +00:00
|
|
|
end
|
2016-03-06 14:28:54 +00:00
|
|
|
|
2019-02-10 17:18:32 +00:00
|
|
|
#
|
|
|
|
# Some things should only be done for login terminals
|
|
|
|
# This used to be in etc/config.fish - keep it here to keep the semantics
|
|
|
|
#
|
|
|
|
if status --is-login
|
|
|
|
if command -sq /usr/libexec/path_helper
|
|
|
|
# Adapt construct_path from the macOS /usr/libexec/path_helper
|
|
|
|
# executable for fish; see
|
|
|
|
# https://opensource.apple.com/source/shell_cmds/shell_cmds-203/path_helper/path_helper.c.auto.html .
|
|
|
|
function __fish_macos_set_env -d "set an environment variable like path_helper does (macOS only)"
|
2019-03-30 18:25:09 +00:00
|
|
|
# The first argument is the variable name, the others are the files.
|
|
|
|
# Keep the components already there so we don't change the order
|
|
|
|
set -l result $$argv[1]
|
2019-02-10 17:18:32 +00:00
|
|
|
|
|
|
|
for path_file in $argv[2] $argv[3]/*
|
|
|
|
if [ -f $path_file ]
|
|
|
|
while read -l entry
|
2019-02-14 10:00:47 +00:00
|
|
|
if not contains -- $entry $result
|
2019-02-10 17:18:32 +00:00
|
|
|
set -a result $entry
|
|
|
|
end
|
|
|
|
end <$path_file
|
|
|
|
end
|
2018-03-31 19:01:29 +00:00
|
|
|
end
|
2018-03-28 06:35:41 +00:00
|
|
|
|
2019-02-10 17:18:32 +00:00
|
|
|
set -xg $argv[1] $result
|
|
|
|
end
|
2018-03-28 06:35:41 +00:00
|
|
|
|
2019-02-10 17:18:32 +00:00
|
|
|
__fish_macos_set_env 'PATH' '/etc/paths' '/etc/paths.d'
|
|
|
|
if [ -n "$MANPATH" ]
|
|
|
|
__fish_macos_set_env 'MANPATH' '/etc/manpaths' '/etc/manpaths.d'
|
|
|
|
end
|
|
|
|
functions -e __fish_macos_set_env
|
2018-03-31 19:01:29 +00:00
|
|
|
end
|
2018-03-28 06:35:41 +00:00
|
|
|
|
2016-12-04 04:36:47 +00:00
|
|
|
#
|
|
|
|
# Put linux consoles in unicode mode.
|
|
|
|
#
|
|
|
|
if test "$TERM" = linux
|
2019-02-11 17:08:28 +00:00
|
|
|
and string match -qir '\.UTF' -- $LANG
|
|
|
|
and command -sq unicode_start
|
|
|
|
unicode_start
|
2016-12-04 04:36:47 +00:00
|
|
|
end
|
2016-03-06 14:28:54 +00:00
|
|
|
end
|
2018-03-28 06:35:41 +00:00
|
|
|
|
|
|
|
# Invoke this here to apply the current value of fish_user_path after
|
|
|
|
# PATH is possibly set above.
|
|
|
|
__fish_reconstruct_path
|
2018-04-14 22:11:04 +00:00
|
|
|
|
|
|
|
# Allow %n job expansion to be used with fg/bg/wait
|
|
|
|
# `jobs` is the only one that natively supports job expansion
|
|
|
|
function __fish_expand_pid_args
|
|
|
|
for arg in $argv
|
|
|
|
if string match -qr '^%\d+$' -- $arg
|
|
|
|
# set newargv $newargv (jobs -p $arg)
|
|
|
|
jobs -p $arg
|
|
|
|
if not test $status -eq 0
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
else
|
2018-04-15 04:19:25 +00:00
|
|
|
printf "%s\n" $arg
|
2018-04-14 22:11:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-11 17:08:28 +00:00
|
|
|
for jobbltn in bg fg wait disown
|
|
|
|
function $jobbltn -V jobbltn
|
|
|
|
builtin $jobbltn (__fish_expand_pid_args $argv)
|
2019-02-10 23:01:38 +00:00
|
|
|
end
|
2018-04-16 15:01:34 +00:00
|
|
|
end
|
2019-02-15 01:01:28 +00:00
|
|
|
|
2019-02-11 17:08:28 +00:00
|
|
|
function kill
|
|
|
|
command kill (__fish_expand_pid_args $argv)
|
|
|
|
end
|
2018-04-16 15:01:34 +00:00
|
|
|
|
2018-06-12 20:28:26 +00:00
|
|
|
# As last part of initialization, source the conf directories.
|
|
|
|
# Implement precedence (User > Admin > Extra (e.g. vendors) > Fish) by basically doing "basename".
|
|
|
|
set -l sourcelist
|
2018-10-21 13:42:25 +00:00
|
|
|
for file in $__fish_config_dir/conf.d/*.fish $__fish_sysconf_dir/conf.d/*.fish $__extra_confdir/*.fish
|
2018-06-12 20:28:26 +00:00
|
|
|
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
|