Package
+ pacman -Ssq | sed -e 's/$/\t'$package'/' >$cache_file &
+ return
+ end
- # Zypper needs caching as it is slow
- if type -q -f zypper
- # Use libzypp cache file if available
- if test -f /var/cache/zypp/solv/@System/solv.idx
- cat /var/cache/zypp/solv/*/solv.idx | awk '!/application:|srcpackage:|product:|pattern:|patch:/ {print $1'\t$package'}'
- return
- end
+ # Zypper needs caching as it is slow
+ if type -q -f zypper
+ # Use libzypp cache file if available
+ if test -f /var/cache/zypp/solv/@System/solv.idx
+ awk '!/application:|srcpackage:|product:|pattern:|patch:/ {print $1'\t$package'}' /var/cache/zypp/solv/*/solv.idx
+ return
+ end
- # If the cache is less than five minutes old, we do not recalculate it
+ # If the cache is less than five minutes old, we do not recalculate it
- set -l cache_file $XDG_CACHE_HOME/.zypper-cache.$USER
- if test -f $cache_file
- cat $cache_file
- set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
- set -l max_age 300
- if test $age -lt $max_age
- return
- end
- end
+ set -l cache_file $XDG_CACHE_HOME/.zypper-cache.$USER
+ if test -f $cache_file
+ cat $cache_file
+ set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
+ set -l max_age 300
+ if test $age -lt $max_age
+ return
+ end
+ end
- # Remove package version information from output and pipe into cache file
- zypper --quiet --non-interactive search --type=package | tail -n +4 | sed -r 's/^. \| ((\w|[-_.])+).*/\1\t'$package'/g' > $cache_file &
- return
- end
+ # Remove package version information from output and pipe into cache file
+ zypper --quiet --non-interactive search --type=package | tail -n +4 | sed -r 's/^. \| ((\w|[-_.])+).*/\1\t'$package'/g' >$cache_file &
+ return
+ end
- # yum is slow, just like rpm, so go to the background
- if type -q -f /usr/share/yum-cli/completion-helper.py
+ # yum is slow, just like rpm, so go to the background
+ if type -q -f /usr/share/yum-cli/completion-helper.py
- # If the cache is less than six hours old, we do not recalculate it
+ # If the cache is less than six hours old, we do not recalculate it
- set cache_file $XDG_CACHE_HOME/.yum-cache.$USER
- if test -f $cache_file
- cat $cache_file
- set age (math (date +%s) - (stat -c '%Y' $cache_file))
- set max_age 21600
- if test $age -lt $max_age
- return
- end
- end
+ set cache_file $XDG_CACHE_HOME/.yum-cache.$USER
+ if test -f $cache_file
+ cat $cache_file
+ set age (math (date +%s) - (stat -c '%Y' $cache_file))
+ set max_age 21600
+ if test $age -lt $max_age
+ return
+ end
+ end
- # Remove package version information from output and pipe into cache file
- /usr/share/yum-cli/completion-helper.py list all -d 0 -C | sed "s/\..*/\t$package/" >$cache_file &
- return
- end
+ # Remove package version information from output and pipe into cache file
+ /usr/share/yum-cli/completion-helper.py list all -d 0 -C | sed "s/\..*/\t$package/" >$cache_file &
+ return
+ end
- # Rpm is too slow for this job, so we set it up to do completions
- # as a background job and cache the results.
+ # Rpm is too slow for this job, so we set it up to do completions
+ # as a background job and cache the results.
- if type -q -f rpm
+ if type -q -f rpm
- # If the cache is less than five minutes old, we do not recalculate it
+ # If the cache is less than five minutes old, we do not recalculate it
- set cache_file $XDG_CACHE_HOME/.rpm-cache.$USER
- if test -f $cache_file
- cat $cache_file
- set age (math (date +%s) - (stat -c '%Y' $cache_file))
- set max_age 250
- if test $age -lt $max_age
- return
- end
- end
+ set cache_file $XDG_CACHE_HOME/.rpm-cache.$USER
+ if test -f $cache_file
+ cat $cache_file
+ set age (math (date +%s) - (stat -c '%Y' $cache_file))
+ set max_age 250
+ if test $age -lt $max_age
+ return
+ end
+ end
- # Remove package version information from output and pipe into cache file
- rpm -qa |sed -e 's/-[^-]*-[^-]*$/\t'$package'/' >$cache_file &
- return
- end
+ # Remove package version information from output and pipe into cache file
+ rpm -qa | sed -e 's/-[^-]*-[^-]*$/\t'$package'/' >$cache_file &
+ return
+ end
- # This completes the package name from the portage tree.
- # True for installing new packages. Function for printing
- # installed on the system packages is in completions/emerge.fish
+ # This completes the package name from the portage tree.
+ # True for installing new packages. Function for printing
+ # installed on the system packages is in completions/emerge.fish
- # eix is MUCH faster than emerge so use it if it is available
- if type -q -f eix
- eix --only-names "^"(commandline -tc) | cut -d/ -f2
- return
- else
- # FIXME? Seems to be broken
- if type -q -f emerge
- emerge -s \^(commandline -tc) | __fish_sgrep "^*" |cut -d\ -f3 |cut -d/ -f2
- return
- end
- end
+ # eix is MUCH faster than emerge so use it if it is available
+ if type -q -f eix
+ eix --only-names "^"(commandline -tc) | cut -d/ -f2
+ return
+ else
+ # FIXME? Seems to be broken
+ if type -q -f emerge
+ emerge -s \^(commandline -tc) | __fish_sgrep "^*" | cut -d\ -f3 | cut -d/ -f2
+ return
+ end
+ end
end
diff --git a/share/functions/__fish_print_pacman_repos.fish b/share/functions/__fish_print_pacman_repos.fish
index 1998f7216..92d4919af 100644
--- a/share/functions/__fish_print_pacman_repos.fish
+++ b/share/functions/__fish_print_pacman_repos.fish
@@ -1,3 +1,3 @@
function __fish_print_pacman_repos --description "Print the repositories configured for arch's pacman package manager"
- string replace -r -a "\[(.+)\]" "\1" < /etc/pacman.conf | string match -r -v "^#|options"
+ string replace -r -a "\[(.+)\]" "\1" /dev/null
- return 1
- end
+ # if svn isn't installed then don't do anything
+ if not command -s svn >/dev/null
+ return 1
+ end
- # make sure that this is a svn repo
- set -l checkout_info (command svn info ^/dev/null)
- if [ $status -ne 0 ];
- return
- end
+ # make sure that this is a svn repo
+ set -l checkout_info (command svn info ^/dev/null)
+ if [ $status -ne 0 ]
- # get the current revision number
- printf '(%s%s%s' (set_color $__fish_svn_prompt_color_revision) (__fish_print_svn_rev) (set_color normal)
+ return
+ end
- # resolve the status of the checkout
- # 1. perform `svn status`
- # 2. remove extra lines that aren't necessary
- # 3. cut the output down to the first 7 columns, as these contain the information needed
- set -l svn_status_lines (command svn status | sed -e 's=^Summary of conflicts.*==' -e 's=^ Text conflicts.*==' -e 's=^ Property conflicts.*==' -e 's=^ Tree conflicts.*==' -e 's=.*incoming .* upon update.*==' | cut -c 1-7)
+ # get the current revision number
+ printf '(%s%s%s' (set_color $__fish_svn_prompt_color_revision) (__fish_print_svn_rev) (set_color normal)
- # track the last column to contain a status flag
- set -l last_column 0
+ # resolve the status of the checkout
+ # 1. perform `svn status`
+ # 2. remove extra lines that aren't necessary
+ # 3. cut the output down to the first 7 columns, as these contain the information needed
+ set -l svn_status_lines (command svn status | sed -e 's=^Summary of conflicts.*==' -e 's=^ Text conflicts.*==' -e 's=^ Property conflicts.*==' -e 's=^ Tree conflicts.*==' -e 's=.*incoming .* upon update.*==' | cut -c 1-7)
- # iterate over the 7 columns of output (the 7 columns are defined on `svn help status`)
- for col in (seq 7)
- # get the output for a particular column
- # 1. echo the whole status flag text
- # 2. cut out the current column of characters
- # 3. remove spaces and newline characters
- set -l column_status (printf '%s\n' $svn_status_lines | cut -c $col | tr -d ' \n')
+ # track the last column to contain a status flag
+ set -l last_column 0
- # check that the character count is not zero (this would indicate that there are status flags in this column)
- if [ (count $column_status) -ne 0 ];
- # we only want to display unique status flags (eg: if there are 5 modified files, the prompt should only show the modified status once)
- set -l column_unique_status (echo $column_status | sort | uniq)
- # parse the status flags for this column and create the formatting by calling out to the helper function
- set -l svn_status_flags (__fish_svn_prompt_parse_status $column_unique_status)
+ # iterate over the 7 columns of output (the 7 columns are defined on `svn help status`)
+ for col in (seq 7)
+ # get the output for a particular column
+ # 1. echo the whole status flag text
+ # 2. cut out the current column of characters
+ # 3. remove spaces and newline characters
+ set -l column_status (printf '%s\n' $svn_status_lines | cut -c $col | tr -d ' \n')
- # the default separator is empty
- set -l prompt_separator ""
- for index in (seq (math "$col - $last_column"))
- # the prompt separator variable has to be updated with the number of separators needed to represent empty status columns (eg: if a file has the status "A +" then it should display as "A|||+" in the prompt)
- set prompt_separator $prompt_separator$__fish_svn_prompt_char_separator
- end
+ # check that the character count is not zero (this would indicate that there are status flags in this column)
+ if [ (count $column_status) -ne 0 ]
- # record that the current column was the last one printed to the prompt
- set last_column $col
- # print the separator string then the current column's status flags
- printf '%s%s' $prompt_separator $svn_status_flags
- end
- end
+ # we only want to display unique status flags (eg: if there are 5 modified files, the prompt should only show the modified status once)
+ set -l column_unique_status (echo $column_status | sort -u)
+ # parse the status flags for this column and create the formatting by calling out to the helper function
+ set -l svn_status_flags (__fish_svn_prompt_parse_status $column_unique_status)
- # print the close of the svn status prompt
- printf ')'
-end
\ No newline at end of file
+ # the default separator is empty
+ set -l prompt_separator ""
+ for index in (seq (math "$col - $last_column"))
+ # the prompt separator variable has to be updated with the number of separators needed to represent empty status columns (eg: if a file has the status "A +" then it should display as "A|||+" in the prompt)
+ set prompt_separator $prompt_separator$__fish_svn_prompt_char_separator
+ end
+
+ # record that the current column was the last one printed to the prompt
+ set last_column $col
+ # print the separator string then the current column's status flags
+ printf '%s%s' $prompt_separator $svn_status_flags
+ end
+ end
+
+ # print the close of the svn status prompt
+ printf ')'
+end
diff --git a/share/functions/__fish_systemctl_automounts.fish b/share/functions/__fish_systemctl_automounts.fish
index 614412293..e62b8afc5 100644
--- a/share/functions/__fish_systemctl_automounts.fish
+++ b/share/functions/__fish_systemctl_automounts.fish
@@ -1,9 +1,9 @@
function __fish_systemctl_automounts
- if type -q systemctl
- if __fish_contains_opt user
- systemctl --user list-unit-files --no-legend --type=automount ^/dev/null | cut -f 1 -d ' '
- else
- systemctl list-unit-files --no-legend --type=automount ^/dev/null | cut -f 1 -d ' '
- end
- end
+ if type -q systemctl
+ if __fish_contains_opt user
+ systemctl --user list-unit-files --no-legend --type=automount ^/dev/null | cut -f 1 -d ' '
+ else
+ systemctl list-unit-files --no-legend --type=automount ^/dev/null | cut -f 1 -d ' '
+ end
+ end
end
diff --git a/share/functions/__fish_systemctl_devices.fish b/share/functions/__fish_systemctl_devices.fish
index bad24a19f..082e65d7d 100644
--- a/share/functions/__fish_systemctl_devices.fish
+++ b/share/functions/__fish_systemctl_devices.fish
@@ -1,11 +1,11 @@
function __fish_systemctl_devices
- if type -q systemctl
- if __fish_contains_opt user
- # Devices are usually generated at runtime
- # Therefore show known _units_, not unit-files
- systemctl --user list-units --no-legend --type=device ^/dev/null | cut -f 1 -d ' '
- else
- systemctl list-units --no-legend --type=device ^/dev/null | cut -f 1 -d ' '
- end
- end
+ if type -q systemctl
+ if __fish_contains_opt user
+ # Devices are usually generated at runtime
+ # Therefore show known _units_, not unit-files
+ systemctl --user list-units --no-legend --type=device ^/dev/null | cut -f 1 -d ' '
+ else
+ systemctl list-units --no-legend --type=device ^/dev/null | cut -f 1 -d ' '
+ end
+ end
end
diff --git a/share/functions/__fish_systemctl_mounts.fish b/share/functions/__fish_systemctl_mounts.fish
index b3e7dd6ab..feac7b1a6 100644
--- a/share/functions/__fish_systemctl_mounts.fish
+++ b/share/functions/__fish_systemctl_mounts.fish
@@ -1,9 +1,9 @@
function __fish_systemctl_mounts
- if type -q systemctl
- if __fish_contains_opt user
- systemctl --user list-unit-files --no-legend --type=mount ^/dev/null | cut -f 1 -d ' '
- else
- systemctl list-unit-files --no-legend --type=mount ^/dev/null | cut -f 1 -d ' '
- end
- end
+ if type -q systemctl
+ if __fish_contains_opt user
+ systemctl --user list-unit-files --no-legend --type=mount ^/dev/null | cut -f 1 -d ' '
+ else
+ systemctl list-unit-files --no-legend --type=mount ^/dev/null | cut -f 1 -d ' '
+ end
+ end
end
diff --git a/share/functions/__fish_systemctl_scopes.fish b/share/functions/__fish_systemctl_scopes.fish
index f2f5cbccc..3b705718b 100644
--- a/share/functions/__fish_systemctl_scopes.fish
+++ b/share/functions/__fish_systemctl_scopes.fish
@@ -1,11 +1,11 @@
function __fish_systemctl_scopes
- if type -q systemctl
- if __fish_contains_opt user
- # Scopes are usually generated at runtime
- # Therefore show known _units_, not unit-files
- systemctl --user list-units --no-legend --type=scope ^/dev/null | cut -f 1 -d ' '
- else
- systemctl list-units --no-legend --type=scope ^/dev/null | cut -f 1 -d ' '
- end
- end
+ if type -q systemctl
+ if __fish_contains_opt user
+ # Scopes are usually generated at runtime
+ # Therefore show known _units_, not unit-files
+ systemctl --user list-units --no-legend --type=scope ^/dev/null | cut -f 1 -d ' '
+ else
+ systemctl list-units --no-legend --type=scope ^/dev/null | cut -f 1 -d ' '
+ end
+ end
end
diff --git a/share/functions/__fish_systemctl_service_paths.fish b/share/functions/__fish_systemctl_service_paths.fish
index 5691ee0d0..5208bf8ba 100644
--- a/share/functions/__fish_systemctl_service_paths.fish
+++ b/share/functions/__fish_systemctl_service_paths.fish
@@ -1,9 +1,9 @@
function __fish_systemctl_service_paths
- if type -q systemctl
- if __fish_contains_opt user
- systemctl --user list-unit-files --no-legend --type=path ^/dev/null $argv | cut -f 1 -d ' '
- else
- systemctl list-unit-files --no-legend --type=path ^/dev/null $argv | cut -f 1 -d ' '
- end
- end
+ if type -q systemctl
+ if __fish_contains_opt user
+ systemctl --user list-unit-files --no-legend --type=path ^/dev/null $argv | cut -f 1 -d ' '
+ else
+ systemctl list-unit-files --no-legend --type=path ^/dev/null $argv | cut -f 1 -d ' '
+ end
+ end
end
diff --git a/share/functions/__fish_systemctl_services.fish b/share/functions/__fish_systemctl_services.fish
index ae779828c..c80f7333d 100644
--- a/share/functions/__fish_systemctl_services.fish
+++ b/share/functions/__fish_systemctl_services.fish
@@ -1,13 +1,13 @@
function __fish_systemctl_services
- if type -q systemctl
- if __fish_contains_opt user
- systemctl --user list-unit-files --no-legend --type=service ^/dev/null $argv | cut -f 1 -d ' '
- systemctl --user list-units --state=loaded --no-legend --type=service ^/dev/null | cut -f 1 -d ' '
- else
- # list-unit-files will also show disabled units
- systemctl list-unit-files --no-legend --type=service ^/dev/null $argv | cut -f 1 -d ' '
- # list-units will not show disabled units but will show instances (like wpa_supplicant@wlan0.service)
- systemctl list-units --state=loaded --no-legend --type=service ^/dev/null | cut -f 1 -d ' '
- end
- end
+ if type -q systemctl
+ if __fish_contains_opt user
+ systemctl --user list-unit-files --no-legend --type=service ^/dev/null $argv | cut -f 1 -d ' '
+ systemctl --user list-units --state=loaded --no-legend --type=service ^/dev/null | cut -f 1 -d ' '
+ else
+ # list-unit-files will also show disabled units
+ systemctl list-unit-files --no-legend --type=service ^/dev/null $argv | cut -f 1 -d ' '
+ # list-units will not show disabled units but will show instances (like wpa_supplicant@wlan0.service)
+ systemctl list-units --state=loaded --no-legend --type=service ^/dev/null | cut -f 1 -d ' '
+ end
+ end
end
diff --git a/share/functions/__fish_systemctl_slices.fish b/share/functions/__fish_systemctl_slices.fish
index 40628f98d..4d8ddf6dc 100644
--- a/share/functions/__fish_systemctl_slices.fish
+++ b/share/functions/__fish_systemctl_slices.fish
@@ -1,11 +1,11 @@
function __fish_systemctl_slices
- if type -q systemctl
- if __fish_contains_opt user
- # Slices are usually generated at runtime
- # Therefore show known _units_, not unit-files
- systemctl --user list-units --no-legend --type=slice ^/dev/null | cut -f 1 -d ' '
- else
- systemctl list-units --no-legend --type=slice ^/dev/null | cut -f 1 -d ' '
- end
- end
+ if type -q systemctl
+ if __fish_contains_opt user
+ # Slices are usually generated at runtime
+ # Therefore show known _units_, not unit-files
+ systemctl --user list-units --no-legend --type=slice ^/dev/null | cut -f 1 -d ' '
+ else
+ systemctl list-units --no-legend --type=slice ^/dev/null | cut -f 1 -d ' '
+ end
+ end
end
diff --git a/share/functions/__fish_systemctl_snapshots.fish b/share/functions/__fish_systemctl_snapshots.fish
index 7b6cb5ee9..7017d8075 100644
--- a/share/functions/__fish_systemctl_snapshots.fish
+++ b/share/functions/__fish_systemctl_snapshots.fish
@@ -1,12 +1,12 @@
function __fish_systemctl_snapshots
- if type -q systemctl
- if __fish_contains_opt user
- # Snapshots are usually generated at runtime
- # Therefore show known _units_, not unit-files
- # They are also often not loaded, so add "--all"
- systemctl --user list-units --all --no-legend --type=snapshot ^/dev/null | cut -f 1 -d ' '
- else
- systemctl list-units --all --no-legend --type=snapshot ^/dev/null | cut -f 1 -d ' '
- end
- end
+ if type -q systemctl
+ if __fish_contains_opt user
+ # Snapshots are usually generated at runtime
+ # Therefore show known _units_, not unit-files
+ # They are also often not loaded, so add "--all"
+ systemctl --user list-units --all --no-legend --type=snapshot ^/dev/null | cut -f 1 -d ' '
+ else
+ systemctl list-units --all --no-legend --type=snapshot ^/dev/null | cut -f 1 -d ' '
+ end
+ end
end
diff --git a/share/functions/__fish_systemctl_sockets.fish b/share/functions/__fish_systemctl_sockets.fish
index d45dfc1b3..5358eaf4c 100644
--- a/share/functions/__fish_systemctl_sockets.fish
+++ b/share/functions/__fish_systemctl_sockets.fish
@@ -1,9 +1,9 @@
function __fish_systemctl_sockets
- if type -q systemctl
- if __fish_contains_opt user
- systemctl --user list-unit-files --no-legend --type=socket ^/dev/null $argv | cut -f 1 -d ' '
- else
- systemctl list-unit-files --no-legend --type=socket ^/dev/null $argv | cut -f 1 -d ' '
- end
- end
+ if type -q systemctl
+ if __fish_contains_opt user
+ systemctl --user list-unit-files --no-legend --type=socket ^/dev/null $argv | cut -f 1 -d ' '
+ else
+ systemctl list-unit-files --no-legend --type=socket ^/dev/null $argv | cut -f 1 -d ' '
+ end
+ end
end
diff --git a/share/functions/__fish_systemctl_swaps.fish b/share/functions/__fish_systemctl_swaps.fish
index 57df43676..91547f752 100644
--- a/share/functions/__fish_systemctl_swaps.fish
+++ b/share/functions/__fish_systemctl_swaps.fish
@@ -1,9 +1,9 @@
function __fish_systemctl_swaps
- if type -q systemctl
- if __fish_contains_opt user
- systemctl --user list-unit-files --no-legend --type=swap ^/dev/null | cut -f 1 -d ' '
- else
- systemctl list-unit-files --no-legend --type=swap ^/dev/null | cut -f 1 -d ' '
- end
- end
+ if type -q systemctl
+ if __fish_contains_opt user
+ systemctl --user list-unit-files --no-legend --type=swap ^/dev/null | cut -f 1 -d ' '
+ else
+ systemctl list-unit-files --no-legend --type=swap ^/dev/null | cut -f 1 -d ' '
+ end
+ end
end
diff --git a/share/functions/__fish_systemctl_targets.fish b/share/functions/__fish_systemctl_targets.fish
index c63afdea4..d444d0cb6 100644
--- a/share/functions/__fish_systemctl_targets.fish
+++ b/share/functions/__fish_systemctl_targets.fish
@@ -1,9 +1,9 @@
function __fish_systemctl_targets
- if type -q systemctl
- if __fish_contains_opt user
- systemctl --user list-unit-files --no-legend --type=target ^/dev/null | cut -f 1 -d ' '
- else
- systemctl list-unit-files --no-legend --type=target ^/dev/null | cut -f 1 -d ' '
- end
- end
+ if type -q systemctl
+ if __fish_contains_opt user
+ systemctl --user list-unit-files --no-legend --type=target ^/dev/null | cut -f 1 -d ' '
+ else
+ systemctl list-unit-files --no-legend --type=target ^/dev/null | cut -f 1 -d ' '
+ end
+ end
end
diff --git a/share/functions/__fish_systemctl_timers.fish b/share/functions/__fish_systemctl_timers.fish
index 1dea2dc18..726a7100a 100644
--- a/share/functions/__fish_systemctl_timers.fish
+++ b/share/functions/__fish_systemctl_timers.fish
@@ -1,9 +1,9 @@
function __fish_systemctl_timers
- if type -q systemctl
- if __fish_contains_opt user
- systemctl --user list-unit-files --no-legend --type=timer ^/dev/null $argv | cut -f 1 -d ' '
- else
- systemctl list-unit-files --no-legend --type=timer ^/dev/null $argv | cut -f 1 -d ' '
- end
- end
+ if type -q systemctl
+ if __fish_contains_opt user
+ systemctl --user list-unit-files --no-legend --type=timer ^/dev/null $argv | cut -f 1 -d ' '
+ else
+ systemctl list-unit-files --no-legend --type=timer ^/dev/null $argv | cut -f 1 -d ' '
+ end
+ end
end
diff --git a/share/functions/__fish_systemd_machine_images.fish b/share/functions/__fish_systemd_machine_images.fish
index 8ff0a69d1..c14865a0a 100644
--- a/share/functions/__fish_systemd_machine_images.fish
+++ b/share/functions/__fish_systemd_machine_images.fish
@@ -1,5 +1,7 @@
# Like for running machines, I'm assuming machinectl doesn't allow spaces in image names
# This does not include the special image ".host" since it isn't valid for most operations
function __fish_systemd_machine_images
- machinectl --no-legend --no-pager list-images | while read -l a b; echo $a; end
+ machinectl --no-legend --no-pager list-images | while read -l a b
+ echo $a
+ end
end
diff --git a/share/functions/__fish_systemd_machines.fish b/share/functions/__fish_systemd_machines.fish
index 09becb2d3..a4ab375f7 100644
--- a/share/functions/__fish_systemd_machines.fish
+++ b/share/functions/__fish_systemd_machines.fish
@@ -1,4 +1,6 @@
# It seems machinectl will eliminate spaces from machine names so we don't need to handle that
function __fish_systemd_machines
- machinectl --no-legend --no-pager list --all | while read -l a b; echo $a; end
+ machinectl --no-legend --no-pager list --all | while read -l a b
+ echo $a
+ end
end
diff --git a/share/functions/__fish_test_arg.fish b/share/functions/__fish_test_arg.fish
index 6ebe8fb0b..695c96866 100644
--- a/share/functions/__fish_test_arg.fish
+++ b/share/functions/__fish_test_arg.fish
@@ -3,7 +3,7 @@ function __fish_test_arg --description "Test if the token under the cursor match
switch (commandline -ct)
case $argv
return 0
- end
+ end
return 1
end
diff --git a/share/functions/__fish_toggle_comment_commandline.fish b/share/functions/__fish_toggle_comment_commandline.fish
index 8bdd7e822..d6cba8445 100644
--- a/share/functions/__fish_toggle_comment_commandline.fish
+++ b/share/functions/__fish_toggle_comment_commandline.fish
@@ -13,5 +13,6 @@ function __fish_toggle_comment_commandline --description 'Comment/uncomment the
end
set -l cmdlines (printf '%s\n' '#'$cmdlines | string replace -r '^##' '')
commandline -r $cmdlines
- string match -q '#*' $cmdlines[1]; and commandline -f execute
+ string match -q '#*' $cmdlines[1]
+ and commandline -f execute
end
diff --git a/share/functions/__fish_urlencode.fish b/share/functions/__fish_urlencode.fish
index df07eee03..0e336813e 100644
--- a/share/functions/__fish_urlencode.fish
+++ b/share/functions/__fish_urlencode.fish
@@ -1,22 +1,26 @@
function __fish_urlencode --description "URL-encode stdin"
- set -l join ''
- set -l chars
- # Set locale to C and IFS to "" in order to split a line into bytes.
- while begin; set -lx LC_ALL C; set -lx IFS ''; read -az chars; end
- printf '%s' $join
- # chomp off a trailing newline
- if test "$chars[-1]" = \n
- set -e chars[-1]
- set join '%0A%00'
- else
- set join '%00'
- end
- for c in $chars
- if string match -q -r '[/._~A-Za-z0-9-]' $c
- printf '%s' $c
- else
- printf '%%%02X' "'$c"
- end
- end
- end
+ set -l join ''
+ set -l chars
+ # Set locale to C and IFS to "" in order to split a line into bytes.
+ while begin
+ set -lx LC_ALL C
+ set -lx IFS ''
+ read -az chars
+ end
+ printf '%s' $join
+ # chomp off a trailing newline
+ if test "$chars[-1]" = \n
+ set -e chars[-1]
+ set join '%0A%00'
+ else
+ set join '%00'
+ end
+ for c in $chars
+ if string match -q -r '[/._~A-Za-z0-9-]' $c
+ printf '%s' $c
+ else
+ printf '%%%02X' "'$c"
+ end
+ end
+ end
end
diff --git a/share/functions/__fish_use_subcommand.fish b/share/functions/__fish_use_subcommand.fish
index 1ec2398b1..dd262c15f 100644
--- a/share/functions/__fish_use_subcommand.fish
+++ b/share/functions/__fish_use_subcommand.fish
@@ -1,14 +1,14 @@
function __fish_use_subcommand -d "Test if a non-switch argument has been given in the current commandline"
- set -l cmd (commandline -poc)
- set -e cmd[1]
- for i in $cmd
- switch $i
- case '-*'
- continue
- end
- return 1
- end
- return 0
+ set -l cmd (commandline -poc)
+ set -e cmd[1]
+ for i in $cmd
+ switch $i
+ case '-*'
+ continue
+ end
+ return 1
+ end
+ return 0
end
diff --git a/share/functions/__fish_vcs_prompt.fish b/share/functions/__fish_vcs_prompt.fish
index 6695cfbaa..04101a73b 100644
--- a/share/functions/__fish_vcs_prompt.fish
+++ b/share/functions/__fish_vcs_prompt.fish
@@ -1,5 +1,5 @@
function __fish_vcs_prompt --description "Print the prompts for all available vcsen"
- __fish_git_prompt
- __fish_hg_prompt
- __fish_svn_prompt
+ __fish_git_prompt
+ __fish_hg_prompt
+ __fish_svn_prompt
end
diff --git a/share/functions/__terlar_git_prompt.fish b/share/functions/__terlar_git_prompt.fish
index 9b3c84a85..32ffff9e9 100644
--- a/share/functions/__terlar_git_prompt.fish
+++ b/share/functions/__terlar_git_prompt.fish
@@ -21,63 +21,70 @@ set -g fish_prompt_git_status_unmerged '!'
set -g fish_prompt_git_status_order added modified renamed copied deleted untracked unmerged
function __terlar_git_prompt --description 'Write out the git prompt'
- # If git isn't installed, there's nothing we can do
- # Return 1 so the calling prompt can deal with it
- if not command -s git >/dev/null
- return 1
- end
- set -l branch (git rev-parse --abbrev-ref HEAD ^/dev/null)
- if test -z $branch
- return
- end
+ # If git isn't installed, there's nothing we can do
+ # Return 1 so the calling prompt can deal with it
+ if not command -s git >/dev/null
+ return 1
+ end
+ set -l branch (git rev-parse --abbrev-ref HEAD ^/dev/null)
+ if test -z $branch
+ return
+ end
- echo -n '|'
+ echo -n '|'
- set -l index (git status --porcelain ^/dev/null|cut -c 1-2|sort -u)
+ set -l index (git status --porcelain ^/dev/null|cut -c 1-2|sort -u)
+
+ if test -z "$index"
+ set_color $fish_color_git_clean
+ echo -n $branch'✓'
+ set_color normal
+ return
+ end
+
+ set -l gs
+ set -l staged
+
+ for i in $index
+ if echo $i | grep '^[AMRCD]' >/dev/null
+ set staged 1
+ end
+
+ switch $i
+ case 'A '
+ set gs $gs added
+ case 'M ' ' M'
+ set gs $gs modified
+ case 'R '
+ set gs $gs renamed
+ case 'C '
+ set gs $gs copied
+ case 'D ' ' D'
+ set gs $gs deleted
+ case '\?\?'
+ set gs $gs untracked
+ case 'U*' '*U' 'DD' 'AA'
+ set gs $gs unmerged
+ end
+ end
+
+ if set -q staged[1]
+ set_color $fish_color_git_staged
+ else
+ set_color $fish_color_git_dirty
+ end
+
+ echo -n $branch'âš¡'
+
+ for i in $fish_prompt_git_status_order
+ if contains $i in $gs
+ set -l color_name fish_color_git_$i
+ set -l status_name fish_prompt_git_status_$i
+
+ set_color $$color_name
+ echo -n $$status_name
+ end
+ end
- if test -z "$index"
- set_color $fish_color_git_clean
- echo -n $branch'✓'
set_color normal
- return
- end
-
- set -l gs
- set -l staged
-
- for i in $index
- if echo $i | grep '^[AMRCD]' >/dev/null
- set staged 1
- end
-
- switch $i
- case 'A ' ; set gs $gs added
- case 'M ' ' M' ; set gs $gs modified
- case 'R ' ; set gs $gs renamed
- case 'C ' ; set gs $gs copied
- case 'D ' ' D' ; set gs $gs deleted
- case '\?\?' ; set gs $gs untracked
- case 'U*' '*U' 'DD' 'AA'; set gs $gs unmerged
- end
- end
-
- if set -q staged[1]
- set_color $fish_color_git_staged
- else
- set_color $fish_color_git_dirty
- end
-
- echo -n $branch'âš¡'
-
- for i in $fish_prompt_git_status_order
- if contains $i in $gs
- set -l color_name fish_color_git_$i
- set -l status_name fish_prompt_git_status_$i
-
- set_color $$color_name
- echo -n $$status_name
- end
- end
-
- set_color normal
end
diff --git a/share/functions/abbr.fish b/share/functions/abbr.fish
index cdb528aef..e09651c58 100644
--- a/share/functions/abbr.fish
+++ b/share/functions/abbr.fish
@@ -1,155 +1,200 @@
function abbr --description "Manage abbreviations"
- # parse arguments
- set -l mode
- set -l mode_flag # the flag that was specified, for better errors
- set -l mode_arg
- set -l needs_arg no
- while set -q argv[1]
- set -l new_mode
- switch $argv[1]
- case '-h' '--help'
- __fish_print_help abbr
- return 0
- case '-a' '--add'
- set new_mode add
- set needs_arg multi
- case '-e' '--erase'
- set new_mode erase
- set needs_arg single
- case '-l' '--list'
- set new_mode list
- case '-s' '--show'
- set new_mode show
- case '--'
- set -e argv[1]
- break
- case '-*'
- printf ( _ "%s: invalid option -- %s\n" ) abbr $argv[1] >&2
- return 1
- case '*'
- break
- end
- if test -n "$mode" -a -n "$new_mode"
- # we're trying to set two different modes
- printf ( _ "%s: %s cannot be specified along with %s\n" ) abbr $argv[1] $mode_flag >&2
- return 1
- end
- set mode $new_mode
- set mode_flag $argv[1]
- set -e argv[1]
- end
+ # parse arguments
+ set -l mode
+ set -l mode_flag # the flag that was specified, for better errors
+ set -l mode_arg
+ set -l needs_arg no
+ while set -q argv[1]
+ set -l new_mode
+ switch $argv[1]
+ case '-h' '--help'
+ __fish_print_help abbr
+ return 0
+ case '-a' '--add'
+ set new_mode add
+ set needs_arg multi
+ case '-r' '--rename'
+ set new_mode rename
+ set needs_arg double
+ case '-e' '--erase'
+ set new_mode erase
+ set needs_arg single
+ case '-l' '--list'
+ set new_mode list
+ case '-s' '--show'
+ set new_mode show
+ case '--'
+ set -e argv[1]
+ break
+ case '-*'
+ printf ( _ "%s: invalid option -- %s\n" ) abbr $argv[1] >&2
+ return 1
+ case '*'
+ break
+ end
+ if test -n "$mode" -a -n "$new_mode"
+ # we're trying to set two different modes
+ printf ( _ "%s: %s cannot be specified along with %s\n" ) abbr $argv[1] $mode_flag >&2
+ return 1
+ end
+ set mode $new_mode
+ set mode_flag $argv[1]
+ set -e argv[1]
+ end
- # If run with no options, treat it like --add if we have an argument, or
- # --show if we do not have an argument
- if not set -q mode[1]
- if set -q argv[1]
- set mode add
- set needs_arg multi
- else
- set mode show
- end
- end
+ # If run with no options, treat it like --add if we have an argument, or
+ # --show if we do not have an argument
+ if not set -q mode[1]
+ if set -q argv[1]
+ set mode add
+ set needs_arg multi
+ else
+ set mode show
+ end
+ end
- if test $needs_arg = single
- set mode_arg $argv[1]
- set needs_arg no
- set -e argv[1]
- else if test $needs_arg = multi
- set mode_arg $argv
- set needs_arg no
- set -e argv
- end
- if test $needs_arg != no
- printf ( _ "%s: option requires an argument -- %s\n" ) abbr $mode_flag >&2
- return 1
- end
-
- # none of our modes want any excess arguments
- if set -q argv[1]
- printf ( _ "%s: Unexpected argument -- %s\n" ) abbr $argv[1] >&2
- return 1
- end
+ if test $needs_arg = single
+ set mode_arg $argv[1]
+ set needs_arg no
+ set -e argv[1]
+ else if test $needs_arg = double
+ # Pull the two parameters from argv.
+ # * leave argv non-empty, if there are more than two arguments
+ # * leave needs_arg set to double if there is not enough arguments
+ if set -q argv[1]
+ set param1 $argv[1]
+ set -e argv[1]
+ if set -q argv[1]
+ set param2 $argv[1]
+ set needs_arg no
+ set -e argv[1]
+ end
+ end
+ else if test $needs_arg = multi
+ set mode_arg $argv
+ set needs_arg no
+ set -e argv
+ end
+ if test $needs_arg != no
+ printf ( _ "%s: option requires an argument -- %s\n" ) abbr $mode_flag >&2
+ return 1
+ end
- switch $mode
- case 'add'
- # Convert from old "key=value" syntax
- # TODO: This should be removed later
- if not set -q mode_arg[2]; and string match -qr '^[^ ]+=' -- $mode_arg
- set mode_arg (string split "=" -- $mode_arg)
- end
+ # none of our modes want any excess arguments
+ if set -q argv[1]
+ printf ( _ "%s: Unexpected argument -- %s\n" ) abbr $argv[1] >&2
+ return 1
+ end
- # Bail out early if the exact abbr is already in
- contains -- "$mode_arg" $fish_user_abbreviations; and return 0
- set -l key $mode_arg[1]
- set -e mode_arg[1]
- set -l value "$mode_arg"
- # Because we later store "$key $value", there can't be any spaces in the key
- if string match -q "* *" -- $key
- printf ( _ "%s: abbreviation cannot have spaces in the key\n" ) abbr >&2
- return 1
- end
- if test -z "$value"
- printf ( _ "%s: abbreviation must have a value\n" ) abbr >&2
- return 1
- end
- if set -l idx (__fish_abbr_get_by_key $key)
- # erase the existing abbreviation
- set -e fish_user_abbreviations[$idx]
- end
- if not set -q fish_user_abbreviations
- # initialize as a universal variable, so we can skip the -U later
- # and therefore work properly if someone sets this as a global variable
- set -U fish_user_abbreviations
- end
- set fish_user_abbreviations $fish_user_abbreviations "$key $value"
- return 0
+ switch $mode
+ case 'add'
+ # Convert from old "key=value" syntax
+ # TODO: This should be removed later
+ if not set -q mode_arg[2]
+ and string match -qr '^[^ ]+=' -- $mode_arg
+ set mode_arg (string split "=" -- $mode_arg)
+ end
- case 'erase'
- if set -l idx (__fish_abbr_get_by_key $mode_arg)
- set -e fish_user_abbreviations[$idx]
- return 0
- else
- printf ( _ "%s: no such abbreviation '%s'\n" ) abbr $mode_arg >&2
- return 2
- end
+ # Bail out early if the exact abbr is already in
+ contains -- "$mode_arg" $fish_user_abbreviations
+ and return 0
+ set -l key $mode_arg[1]
+ set -e mode_arg[1]
+ set -l value "$mode_arg"
+ # Because we later store "$key $value", there can't be any spaces in the key
+ if string match -q "* *" -- $key
+ printf ( _ "%s: abbreviation cannot have spaces in the key\n" ) abbr >&2
+ return 1
+ end
+ if test -z "$value"
+ printf ( _ "%s: abbreviation must have a value\n" ) abbr >&2
+ return 1
+ end
+ if set -l idx (__fish_abbr_get_by_key $key)
+ # erase the existing abbreviation
+ set -e fish_user_abbreviations[$idx]
+ end
+ if not set -q fish_user_abbreviations
+ # initialize as a universal variable, so we can skip the -U later
+ # and therefore work properly if someone sets this as a global variable
+ set -U fish_user_abbreviations
+ end
+ set fish_user_abbreviations $fish_user_abbreviations "$key $value"
+ return 0
- case 'show'
- for i in $fish_user_abbreviations
- set -l opt_double_dash
- set -l kv (string split " " -m 1 -- $i)
- set -l key $kv[1]
- set -l value $kv[2]
-
- # Check to see if either key or value has a leading dash
- # If so, we need to write --
- string match -q -- '-*' $key $value; and set opt_double_dash '--'
- echo abbr $opt_double_dash (string escape -- $key $value)
- end
- return 0
+ case 'rename'
+ set -l old_name $param1
+ set -l new_name $param2
- case 'list'
- for i in $fish_user_abbreviations
- set -l key (string split " " -m 1 -- $i)[1]
- printf "%s\n" $key
- end
- return 0
- end
+ # if the target name already exists, throw an error
+ if set -l idx (__fish_abbr_get_by_key $new_name)
+ printf ( _ "%s: abbreviation '%s' already exists, cannot rename\n" ) abbr $new_name >&2
+ return 2
+ end
+
+ # Because we later store "$key $value", there can't be any spaces in the key
+ if string match -q "* *" -- $new_name
+ printf ( _ "%s: abbreviation cannot have spaces in the key\n" ) abbr >&2
+ return 1
+ end
+
+ set -l idx (__fish_abbr_get_by_key $old_name)
+ or begin
+ printf ( _ "%s: no such abbreviation '%s'\n" ) abbr $old_name >&2
+ return 2
+ end
+
+ set -l value (string split " " -m 1 -- $fish_user_abbreviations[$idx])[2]
+ set fish_user_abbreviations[$idx] "$new_name $value"
+ return 0
+
+ case 'erase'
+ if set -l idx (__fish_abbr_get_by_key $mode_arg)
+ set -e fish_user_abbreviations[$idx]
+ return 0
+ else
+ printf ( _ "%s: no such abbreviation '%s'\n" ) abbr $mode_arg >&2
+ return 2
+ end
+
+ case 'show'
+ for i in $fish_user_abbreviations
+ set -l opt_double_dash
+ set -l kv (string split " " -m 1 -- $i)
+ set -l key $kv[1]
+ set -l value $kv[2]
+
+ # Check to see if either key or value has a leading dash
+ # If so, we need to write --
+ string match -q -- '-*' $key $value
+ and set opt_double_dash '--'
+ echo abbr $opt_double_dash (string escape -- $key $value)
+ end
+ return 0
+
+ case 'list'
+ for i in $fish_user_abbreviations
+ set -l key (string split " " -m 1 -- $i)[1]
+ printf "%s\n" $key
+ end
+ return 0
+ end
end
function __fish_abbr_get_by_key
- if not set -q argv[1]
- echo "__fish_abbr_get_by_key: expected one argument, got none" >&2
- return 2
- end
- # Going through all entries is still quicker than calling `seq`
- set -l keys
- for kv in $fish_user_abbreviations
- # If this does not match, we have screwed up before and the error should be reported
- set keys $keys (string split " " -m 1 -- $kv)[1]
- end
- if set -l idx (contains -i -- $argv[1] $keys)
- echo $idx
- return 0
- end
- return 1
+ if not set -q argv[1]
+ echo "__fish_abbr_get_by_key: expected one argument, got none" >&2
+ return 2
+ end
+ # Going through all entries is still quicker than calling `seq`
+ set -l keys
+ for kv in $fish_user_abbreviations
+ # If this does not match, we have screwed up before and the error should be reported
+ set keys $keys (string split " " -m 1 -- $kv)[1]
+ end
+ if set -l idx (contains -i -- $argv[1] $keys)
+ echo $idx
+ return 0
+ end
+ return 1
end
diff --git a/share/functions/alias.fish b/share/functions/alias.fish
index 41d1b7ae8..5566e2487 100644
--- a/share/functions/alias.fish
+++ b/share/functions/alias.fish
@@ -1,5 +1,5 @@
function alias --description 'Creates a function wrapping a command'
- if count $argv > /dev/null
+ if count $argv >/dev/null
switch $argv[1]
case -h --h --he --hel --help
__fish_print_help alias
diff --git a/share/functions/contains_seq.fish b/share/functions/contains_seq.fish
index 9fae7cacf..d3a20e1c8 100644
--- a/share/functions/contains_seq.fish
+++ b/share/functions/contains_seq.fish
@@ -1,46 +1,46 @@
function contains_seq --description 'Return true if array contains a sequence'
- set -l printnext
- switch $argv[1]
- case --printnext
- set printnext[1] 1
- set -e argv[1]
- end
- set -l pattern
- set -l string
- set -l dest pattern
- for i in $argv
- if test "$i" = --
- set dest string
- continue
- end
- set $dest $$dest $i
- end
- set -l nomatch 1
- set -l i 1
- for s in $string
- if set -q printnext[2]
- return 0
- end
- if test "$s" = "$pattern[$i]"
- set -e nomatch[1]
- set i (math $i + 1)
- if not set -q pattern[$i]
- if set -q printnext[1]
- set printnext[2] 1
- continue
- end
- return 0
- end
- else
- if not set -q nomatch[1]
- set nomatch 1
- set i 1
- end
- end
- end
- if set -q printnext[1]
- echo ''
- end
- set -q printnext[2]
+ set -l printnext
+ switch $argv[1]
+ case --printnext
+ set printnext[1] 1
+ set -e argv[1]
+ end
+ set -l pattern
+ set -l string
+ set -l dest pattern
+ for i in $argv
+ if test "$i" = --
+ set dest string
+ continue
+ end
+ set $dest $$dest $i
+ end
+ set -l nomatch 1
+ set -l i 1
+ for s in $string
+ if set -q printnext[2]
+ return 0
+ end
+ if test "$s" = "$pattern[$i]"
+ set -e nomatch[1]
+ set i (math $i + 1)
+ if not set -q pattern[$i]
+ if set -q printnext[1]
+ set printnext[2] 1
+ continue
+ end
+ return 0
+ end
+ else
+ if not set -q nomatch[1]
+ set nomatch 1
+ set i 1
+ end
+ end
+ end
+ if set -q printnext[1]
+ echo ''
+ end
+ set -q printnext[2]
end
diff --git a/share/functions/delete-or-exit.fish b/share/functions/delete-or-exit.fish
index 2a8d7286c..5a83ab8ac 100644
--- a/share/functions/delete-or-exit.fish
+++ b/share/functions/delete-or-exit.fish
@@ -7,17 +7,17 @@
function delete-or-exit
- set -l cmd (commandline)
+ set -l cmd (commandline)
- switch "$cmd"
+ switch "$cmd"
- case ''
- exit 0
+ case ''
+ exit 0
- case '*'
- commandline -f delete-char
+ case '*'
+ commandline -f delete-char
- end
+ end
end
diff --git a/share/functions/dirs.fish b/share/functions/dirs.fish
index 207f66328..7fd5b0494 100644
--- a/share/functions/dirs.fish
+++ b/share/functions/dirs.fish
@@ -1,18 +1,15 @@
function dirs --description 'Print directory stack'
- # process options
- if count $argv >/dev/null
- switch $argv[1]
- case -c
- # clear directory stack
- set -e -g dirstack
- return 0
- end
+ # process options
+ if set -q argv[1]
+ switch $argv[1]
+ case -c
+ # clear directory stack
+ set -e -g dirstack
+ return 0
end
+ end
- # replace $HOME with ~
- echo -n (echo (command pwd) | sed -e "s|^$HOME|~|")" "
- for i in $dirstack
- echo -n (echo $i | sed -e "s|^$HOME|~|")" "
- end
- echo
+ # replace $HOME with ~
+ string replace -r '^'"$HOME"'($|/)' '~$1' -- $PWD $dirstack | string join " "
+ echo
end
diff --git a/share/functions/down-or-search.fish b/share/functions/down-or-search.fish
index 967342391..b21232417 100644
--- a/share/functions/down-or-search.fish
+++ b/share/functions/down-or-search.fish
@@ -1,28 +1,28 @@
function down-or-search -d "Depending on cursor position and current mode, either search forward or move down one line"
- # If we are already in search mode, continue
- if commandline --search-mode
- commandline -f history-search-forward
- return
- end
+ # If we are already in search mode, continue
+ if commandline --search-mode
+ commandline -f history-search-forward
+ return
+ end
- # If we are navigating the pager, then up always navigates
- if commandline --paging-mode
- commandline -f down-line
- return
- end
+ # If we are navigating the pager, then up always navigates
+ if commandline --paging-mode
+ commandline -f down-line
+ return
+ end
- # We are not already in search mode.
- # If we are on the bottom line, start search mode,
- # otherwise move down
- set lineno (commandline -L)
- set line_count (count (commandline))
+ # We are not already in search mode.
+ # If we are on the bottom line, start search mode,
+ # otherwise move down
+ set lineno (commandline -L)
+ set line_count (count (commandline))
- switch $lineno
- case $line_count
- commandline -f history-search-forward
+ switch $lineno
+ case $line_count
+ commandline -f history-search-forward
- case '*'
- commandline -f down-line
- end
+ case '*'
+ commandline -f down-line
+ end
end
diff --git a/share/functions/edit_command_buffer.fish b/share/functions/edit_command_buffer.fish
new file mode 100644
index 000000000..c46f11e20
--- /dev/null
+++ b/share/functions/edit_command_buffer.fish
@@ -0,0 +1,44 @@
+function edit_command_buffer --description 'Edit the command buffer in an external editor'
+ set -l f (mktemp)
+ if set -q f[1]
+ mv $f $f.fish
+ set f $f.fish
+ else
+ # We should never execute this block but better to be paranoid.
+ if set -q TMPDIR
+ set f $TMPDIR/fish.(echo %self).fish
+ else
+ set f /tmp/fish.(echo %self).fish
+ end
+ touch $f
+ or return 1
+ end
+
+ # Edit the command line with the users preferred editor or vim or emacs.
+ commandline -b >$f
+ if set -q VISUAL
+ eval $VISUAL $f
+ else if set -q EDITOR
+ eval $EDITOR $f
+ else
+ echo
+ echo (_ 'External editor requested but $VISUAL or $EDITOR not set.')
+ echo (_ 'Please set VISUAL or EDITOR to your preferred editor.')
+ commandline -f repaint
+ command rm $f
+ return 1
+ end
+
+ # Here we're checking the exit status of the editor.
+ if test $status -eq 0 -a -s $f
+ # Set the command to the output of the edited command and move the cursor to the
+ # end of the edited command.
+ commandline -r -- (cat $f)
+ commandline -C 999999
+ else
+ echo
+ echo (_ "Ignoring the output of your editor since its exit status was non-zero")
+ echo (_ "or the file was empty")
+ end
+ command rm $f
+end
diff --git a/share/functions/eval.fish b/share/functions/eval.fish
index 052d41718..fc5f5aef4 100644
--- a/share/functions/eval.fish
+++ b/share/functions/eval.fish
@@ -1,65 +1,65 @@
function eval -S -d "Evaluate parameters as a command"
- # keep a copy of the previous $status and use restore_status
- # to preserve the status in case the block that is evaluated
- # does not modify the status itself.
- set -l status_copy $status
- function __fish_restore_status
- return $argv[1]
- end
+ # keep a copy of the previous $status and use restore_status
+ # to preserve the status in case the block that is evaluated
+ # does not modify the status itself.
+ set -l status_copy $status
+ function __fish_restore_status
+ return $argv[1]
+ end
- if not set -q argv[2]
- # like most builtins, we only check for -h/--help
- # if we only have a single argument
- switch "$argv[1]"
- case -h --help
- __fish_print_help eval
- return 0
- end
- end
+ if not set -q argv[2]
+ # like most builtins, we only check for -h/--help
+ # if we only have a single argument
+ switch "$argv[1]"
+ case -h --help
+ __fish_print_help eval
+ return 0
+ end
+ end
- # If we are in an interactive shell, eval should enable full
- # job control since it should behave like the real code was
- # executed. If we don't do this, commands that expect to be
- # used interactively, like less, wont work using eval.
+ # If we are in an interactive shell, eval should enable full
+ # job control since it should behave like the real code was
+ # executed. If we don't do this, commands that expect to be
+ # used interactively, like less, wont work using eval.
- set -l mode
- if status --is-interactive-job-control
- set mode interactive
- else
- if status --is-full-job-control
- set mode full
- else
- set mode none
- end
- end
- if status --is-interactive
- status --job-control full
- end
- __fish_restore_status $status_copy
+ set -l mode
+ if status --is-interactive-job-control
+ set mode interactive
+ else
+ if status --is-full-job-control
+ set mode full
+ else
+ set mode none
+ end
+ end
+ if status --is-interactive
+ status --job-control full
+ end
+ __fish_restore_status $status_copy
- # To eval 'foo', we construct a block "begin ; foo; end <&3 3<&-"
- # Note the redirections are also within the quotes.
- #
- # We then pipe this to 'source 3<&0’.
- #
- # You might expect that the dup2(3, stdin) should overwrite stdin,
- # and therefore prevent 'source' from reading the piped-in block. This doesn't happen
- # because when you pipe to a builtin, we don't overwrite stdin with the read end
- # of the block; instead we set a separate fd in a variable 'builtin_stdin', which is
- # what it reads from. So builtins are magic in that, in pipes, their stdin
- # is not fd 0.
- #
- # ‘source’ does not apply the redirections to itself. Instead it saves them and passes
- # them as block-level redirections to parser.eval(). Ultimately the eval’d code sees
- # the following redirections (in the following order):
- # dup2 0 -> 3
- # dup2 pipe -> 0
- # dup2 3 -> 0
- # where the pipe is the pipe we get from piping ‘echo’ to ‘source’. Thus the redirection
- # effectively makes stdin fd0, instead of the thing that was piped to ‘source’
- echo "begin; $argv "\n" ;end <&3 3<&-" | source 3<&0
- set -l res $status
+ # To eval 'foo', we construct a block "begin ; foo; end <&3 3<&-"
+ # Note the redirections are also within the quotes.
+ #
+ # We then pipe this to 'source 3<&0’.
+ #
+ # You might expect that the dup2(3, stdin) should overwrite stdin,
+ # and therefore prevent 'source' from reading the piped-in block. This doesn't happen
+ # because when you pipe to a builtin, we don't overwrite stdin with the read end
+ # of the block; instead we set a separate fd in a variable 'builtin_stdin', which is
+ # what it reads from. So builtins are magic in that, in pipes, their stdin
+ # is not fd 0.
+ #
+ # ‘source’ does not apply the redirections to itself. Instead it saves them and passes
+ # them as block-level redirections to parser.eval(). Ultimately the eval’d code sees
+ # the following redirections (in the following order):
+ # dup2 0 -> 3
+ # dup2 pipe -> 0
+ # dup2 3 -> 0
+ # where the pipe is the pipe we get from piping ‘echo’ to ‘source’. Thus the redirection
+ # effectively makes stdin fd0, instead of the thing that was piped to ‘source’
+ echo "begin; $argv "\n" ;end <&3 3<&-" | source 3<&0
+ set -l res $status
- status --job-control $mode
- return $res
+ status --job-control $mode
+ return $res
end
diff --git a/share/functions/fish_clipboard_copy.fish b/share/functions/fish_clipboard_copy.fish
index a65efc045..a973e4437 100644
--- a/share/functions/fish_clipboard_copy.fish
+++ b/share/functions/fish_clipboard_copy.fish
@@ -1,5 +1,5 @@
function fish_clipboard_copy
- if type -q pbcopy
+ if type -q pbcopy
commandline | pbcopy
else if type -q xsel
commandline | xsel --clipboard
diff --git a/share/functions/fish_clipboard_paste.fish b/share/functions/fish_clipboard_paste.fish
index c6a4a3e45..318b935d3 100644
--- a/share/functions/fish_clipboard_paste.fish
+++ b/share/functions/fish_clipboard_paste.fish
@@ -1,7 +1,14 @@
function fish_clipboard_paste
- if type -q pbpaste
+ if type -q pbpaste
commandline -i -- (pbpaste)
else if type -q xsel
- commandline -i -- (xsel --clipboard)
+ # Only run `commandline` if `xsel` succeeded.
+ # That way any xsel error is printed (to show e.g. a non-functioning X connection),
+ # but we don't print the redundant (and overly verbose for this) commandline error.
+ # Also require non-empty contents to not clear the buffer.
+ if set -l data (xsel --clipboard)
+ and test -n "$data"
+ commandline -i -- $data
+ end
end
end
diff --git a/share/functions/fish_config.fish b/share/functions/fish_config.fish
index 9bcac866e..48b113c78 100644
--- a/share/functions/fish_config.fish
+++ b/share/functions/fish_config.fish
@@ -1,9 +1,9 @@
function fish_config --description "Launch fish's web based configuration"
- # Support passing an initial tab like "colors" or "functions"
- set -l initial_tab
- if count $argv >/dev/null
- set initial_tab $argv[1]
- end
- set -x __fish_bin_dir $__fish_bin_dir
- eval (string escape $__fish_datadir/tools/web_config/webconfig.py) $initial_tab
+ # Support passing an initial tab like "colors" or "functions"
+ set -l initial_tab
+ if count $argv >/dev/null
+ set initial_tab $argv[1]
+ end
+ set -x __fish_bin_dir $__fish_bin_dir
+ eval (string escape $__fish_datadir/tools/web_config/webconfig.py) $initial_tab
end
diff --git a/share/functions/fish_default_key_bindings.fish b/share/functions/fish_default_key_bindings.fish
index 29fccad2d..008b183cb 100644
--- a/share/functions/fish_default_key_bindings.fish
+++ b/share/functions/fish_default_key_bindings.fish
@@ -1,86 +1,93 @@
-
function fish_default_key_bindings -d "Default (Emacs-like) key bindings for fish"
- if not set -q argv[1]
- # Clear earlier bindings, if any
- bind --erase --all
- if test "$fish_key_bindings" != "fish_default_key_bindings"
- # Allow the user to set the variable universally
- set -q fish_key_bindings; or set -g fish_key_bindings
- set fish_key_bindings fish_default_key_bindings # This triggers the handler, which calls us again and ensures the user_key_bindings are executed
- return
- end
- end
+ if contains -- -h $argv
+ or contains -- --help $argv
+ echo "Sorry but this function doesn't support -h or --help"
+ return 1
+ end
+
+ if not set -q argv[1]
+ bind --erase --all # clear earlier bindings, if any
+ if test "$fish_key_bindings" != "fish_default_key_bindings"
+ # Allow the user to set the variable universally
+ set -q fish_key_bindings
+ or set -g fish_key_bindings
+ # This triggers the handler, which calls us again and ensures the user_key_bindings
+ # are executed.
+ set fish_key_bindings fish_default_key_bindings
+ return
+ end
+ end
# These are shell-specific bindings that we share with vi mode.
__fish_shared_key_bindings $argv
+ or return # protect against invalid $argv
- # This is the default binding, i.e. the one used if no other binding matches
- bind $argv "" self-insert
+ # This is the default binding, i.e. the one used if no other binding matches
+ bind $argv "" self-insert
+ or exit # protect against invalid $argv
- bind $argv \n execute
- bind $argv \r execute
+ bind $argv \n execute
+ bind $argv \r execute
- bind $argv \ck kill-line
+ bind $argv \ck kill-line
- bind $argv \eOC forward-char
- bind $argv \eOD backward-char
- bind $argv \e\[C forward-char
- bind $argv \e\[D backward-char
- bind $argv -k right forward-char
- bind $argv -k left backward-char
+ bind $argv \eOC forward-char
+ bind $argv \eOD backward-char
+ bind $argv \e\[C forward-char
+ bind $argv \e\[D backward-char
+ bind $argv -k right forward-char
+ bind $argv -k left backward-char
- bind $argv -k dc delete-char
- bind $argv -k backspace backward-delete-char
- bind $argv \x7f backward-delete-char
+ bind $argv -k dc delete-char
+ bind $argv -k backspace backward-delete-char
+ bind $argv \x7f backward-delete-char
- # for PuTTY
- # https://github.com/fish-shell/fish-shell/issues/180
- bind $argv \e\[1~ beginning-of-line
- bind $argv \e\[3~ delete-char
- bind $argv \e\[4~ end-of-line
+ # for PuTTY
+ # https://github.com/fish-shell/fish-shell/issues/180
+ bind $argv \e\[1~ beginning-of-line
+ bind $argv \e\[3~ delete-char
+ bind $argv \e\[4~ end-of-line
- # OS X SnowLeopard doesn't have these keys. Don't show an annoying error message.
- bind $argv -k home beginning-of-line 2> /dev/null
- bind $argv -k end end-of-line 2> /dev/null
- bind $argv \e\[3\;2~ backward-delete-char # Mavericks Terminal.app shift-delete
+ # OS X SnowLeopard doesn't have these keys. Don't show an annoying error message.
+ bind $argv -k home beginning-of-line 2>/dev/null
+ bind $argv -k end end-of-line 2>/dev/null
+ bind $argv \e\[3\;2~ backward-delete-char # Mavericks Terminal.app shift-ctrl-delete
- bind $argv \ca beginning-of-line
- bind $argv \ce end-of-line
- bind $argv \ch backward-delete-char
- bind $argv \cp up-or-search
- bind $argv \cn down-or-search
- bind $argv \cf forward-char
- bind $argv \cb backward-char
- bind $argv \ct transpose-chars
- bind $argv \et transpose-words
- bind $argv \eu upcase-word
+ bind $argv \ca beginning-of-line
+ bind $argv \ce end-of-line
+ bind $argv \ch backward-delete-char
+ bind $argv \cp up-or-search
+ bind $argv \cn down-or-search
+ bind $argv \cf forward-char
+ bind $argv \cb backward-char
+ bind $argv \ct transpose-chars
+ bind $argv \et transpose-words
+ bind $argv \eu upcase-word
- # This clashes with __fish_list_current_token
- # bind $argv \el downcase-word
- bind $argv \ec capitalize-word
- bind $argv \e\x7f backward-kill-word
- bind $argv \eb backward-word
- bind $argv \ef forward-word
- bind $argv \e\[1\;5C forward-word
- bind $argv \e\[1\;5D backward-word
- bind $argv -k ppage beginning-of-history
- bind $argv -k npage end-of-history
- bind $argv \e\< beginning-of-buffer
- bind $argv \e\> end-of-buffer
+ # This clashes with __fish_list_current_token
+ # bind $argv \el downcase-word
+ bind $argv \ec capitalize-word
+ bind $argv \e\x7f backward-kill-word
+ bind $argv \eb backward-word
+ bind $argv \ef forward-word
+ bind $argv \e\[1\;5C forward-word
+ bind $argv \e\[1\;5D backward-word
+ bind $argv \e\< beginning-of-buffer
+ bind $argv \e\> end-of-buffer
- bind \ed forward-kill-word
- bind \ed kill-word
+ bind \ed forward-kill-word
+ bind \ed kill-word
- # Ignore some known-bad control sequences
- # https://github.com/fish-shell/fish-shell/issues/1917
- bind \e\[I 'begin;end'
- bind \e\[O 'begin;end'
+ # Ignore some known-bad control sequences
+ # https://github.com/fish-shell/fish-shell/issues/1917
+ bind \e\[I 'begin;end'
+ bind \e\[O 'begin;end'
- # term-specific special bindings
- switch "$TERM"
- case 'rxvt*'
- bind $argv \e\[8~ end-of-line
- bind $argv \eOc forward-word
- bind $argv \eOd backward-word
- end
+ # term-specific special bindings
+ switch "$TERM"
+ case 'rxvt*'
+ bind $argv \e\[8~ end-of-line
+ bind $argv \eOc forward-word
+ bind $argv \eOd backward-word
+ end
end
diff --git a/share/functions/fish_default_mode_prompt.fish b/share/functions/fish_default_mode_prompt.fish
new file mode 100644
index 000000000..638c07f9e
--- /dev/null
+++ b/share/functions/fish_default_mode_prompt.fish
@@ -0,0 +1,23 @@
+function fish_default_mode_prompt --description "Display the default mode for the prompt"
+ # Do nothing if not in vi mode
+ if test "$fish_key_bindings" = "fish_vi_key_bindings"
+ or test "$fish_key_bindings" = "fish_hybrid_key_bindings"
+ switch $fish_bind_mode
+ case default
+ set_color --bold --background red white
+ echo '[N]'
+ case insert
+ set_color --bold --background green white
+ echo '[I]'
+ case replace-one
+ set_color --bold --background green white
+ echo '[R]'
+ case visual
+ set_color --bold --background magenta white
+ echo '[V]'
+ end
+ set_color normal
+ echo -n ' '
+ end
+end
+
diff --git a/share/functions/fish_fallback_prompt.fish b/share/functions/fish_fallback_prompt.fish
index 1910eeaea..d8b976001 100644
--- a/share/functions/fish_fallback_prompt.fish
+++ b/share/functions/fish_fallback_prompt.fish
@@ -3,20 +3,20 @@
# Set the default prompt command.
function fish_fallback_prompt --description "A simple fallback prompt without too much color or special characters for linux VTs"
- set -l color_cwd
- set -l suffix
- switch $USER
- case root toor
- if set -q fish_color_cwd_root
- set color_cwd $fish_color_cwd_root
- else
- set color_cwd $fish_color_cwd
- end
- set suffix '#'
- case '*'
- set color_cwd $fish_color_cwd
- set suffix '>'
- end
+ set -l color_cwd
+ set -l suffix
+ switch $USER
+ case root toor
+ if set -q fish_color_cwd_root
+ set color_cwd $fish_color_cwd_root
+ else
+ set color_cwd $fish_color_cwd
+ end
+ set suffix '#'
+ case '*'
+ set color_cwd $fish_color_cwd
+ set suffix '>'
+ end
- echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix "
+ echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix "
end
diff --git a/share/functions/fish_hybrid_key_bindings.fish b/share/functions/fish_hybrid_key_bindings.fish
new file mode 100644
index 000000000..bf2bbf015
--- /dev/null
+++ b/share/functions/fish_hybrid_key_bindings.fish
@@ -0,0 +1,18 @@
+function fish_hybrid_key_bindings --description "Vi-style bindings that inherit emacs-style bindings in all modes"
+ bind --erase --all # clear earlier bindings, if any
+
+ if test "$fish_key_bindings" != "fish_hybrid_key_bindings"
+ # Allow the user to set the variable universally
+ set -q fish_key_bindings
+ or set -g fish_key_bindings
+ # This triggers the handler, which calls us again and ensures the user_key_bindings
+ # are executed.
+ set fish_key_bindings fish_hybrid_key_bindings
+ return
+ end
+
+ for mode in default insert visual
+ fish_default_key_bindings -M $mode
+ end
+ fish_vi_key_bindings --no-erase
+end
diff --git a/share/functions/fish_indent.fish b/share/functions/fish_indent.fish
index a97e1c2e8..03e30995a 100644
--- a/share/functions/fish_indent.fish
+++ b/share/functions/fish_indent.fish
@@ -1,6 +1,6 @@
# check if command fish_indent works and is the same version that
# came with this fish. This will happen one time.
-command -s fish_indent > /dev/null
+command -s fish_indent >/dev/null
and command fish_indent --version 2>&1 | string match -rq $FISH_VERSION
# if alias doesn't define the function here, this is an autoloaded "nothing".
# the command (if there is one) will be used by default.
diff --git a/share/functions/fish_key_reader.fish b/share/functions/fish_key_reader.fish
index 5a955e13f..0cf5b29a7 100644
--- a/share/functions/fish_key_reader.fish
+++ b/share/functions/fish_key_reader.fish
@@ -1,6 +1,6 @@
# check if command fish_key_reader works and is the same version that
# came with this fish. This will happen one time.
-command -s fish_key_reader > /dev/null
+command -s fish_key_reader >/dev/null
and command fish_key_reader --version 2>&1 | string match -rq $FISH_VERSION
# if alias doesn't define the function here, this is an autoloaded "nothing".
# the command (if there is one) will be used by default.
diff --git a/share/functions/fish_mode_prompt.fish b/share/functions/fish_mode_prompt.fish
index eed75d42d..294ebeebb 100644
--- a/share/functions/fish_mode_prompt.fish
+++ b/share/functions/fish_mode_prompt.fish
@@ -1,22 +1,5 @@
# The fish_mode_prompt function is prepended to the prompt
function fish_mode_prompt --description "Displays the current mode"
- # Do nothing if not in vi mode
- if test "$fish_key_bindings" = "fish_vi_key_bindings"
- switch $fish_bind_mode
- case default
- set_color --bold --background red white
- echo '[N]'
- case insert
- set_color --bold --background green white
- echo '[I]'
- case replace-one
- set_color --bold --background green white
- echo '[R]'
- case visual
- set_color --bold --background magenta white
- echo '[V]'
- end
- set_color normal
- echo -n ' '
- end
+ # To reuse the mode indicator use this function instead
+ fish_default_mode_prompt
end
diff --git a/share/functions/fish_prompt.fish b/share/functions/fish_prompt.fish
index 7f8581971..153d3adbc 100644
--- a/share/functions/fish_prompt.fish
+++ b/share/functions/fish_prompt.fish
@@ -3,20 +3,20 @@
# Set the default prompt command.
function fish_prompt --description "Write out the prompt"
- set -l color_cwd
- set -l suffix
- switch $USER
- case root toor
- if set -q fish_color_cwd_root
- set color_cwd $fish_color_cwd_root
- else
- set color_cwd $fish_color_cwd
- end
- set suffix '#'
- case '*'
- set color_cwd $fish_color_cwd
- set suffix '>'
- end
+ set -l color_cwd
+ set -l suffix
+ switch $USER
+ case root toor
+ if set -q fish_color_cwd_root
+ set color_cwd $fish_color_cwd_root
+ else
+ set color_cwd $fish_color_cwd
+ end
+ set suffix '#'
+ case '*'
+ set color_cwd $fish_color_cwd
+ set suffix '>'
+ end
- echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix "
+ echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix "
end
diff --git a/share/functions/fish_update_completions.fish b/share/functions/fish_update_completions.fish
index 17b47ecb9..0fb007983 100644
--- a/share/functions/fish_update_completions.fish
+++ b/share/functions/fish_update_completions.fish
@@ -1,4 +1,4 @@
function fish_update_completions --description "Update man-page based completions"
- # Clean up old paths
- python -B $__fish_datadir/tools/create_manpage_completions.py --manpath --progress --cleanup-in '~/.config/fish/completions' --cleanup-in '~/.config/fish/generated_completions'
+ # Clean up old paths
+ python -B $__fish_datadir/tools/create_manpage_completions.py --manpath --progress --cleanup-in '~/.config/fish/completions' --cleanup-in '~/.config/fish/generated_completions'
end
diff --git a/share/functions/fish_vi_cursor.fish b/share/functions/fish_vi_cursor.fish
index 1ab8ef25f..0da5e2a0c 100644
--- a/share/functions/fish_vi_cursor.fish
+++ b/share/functions/fish_vi_cursor.fish
@@ -12,18 +12,30 @@ function fish_vi_cursor -d 'Set cursor shape for different vi modes'
# e.g. tmux started in suckless' st (no support) started in konsole.
# But since tmux in konsole seems rather common and that case so uncommon,
# we will just fail there (though it seems that tmux or st swallow it anyway).
- #
+
+ if set -q INSIDE_EMACS
+ return
+ end
+
+ # vte-based terms set $TERM = xterm*, but only gained support relatively recently.
+ # From https://bugzilla.gnome.org/show_bug.cgi?id=720821, it appears it was version 0.40.0
+ if set -q VTE_VERSION
+ and test "$VTE_VERSION" -lt 4000 ^/dev/null
+ return
+ end
+
# We use the `tput` here just to see if terminfo thinks we can change the cursor.
# We cannot use that sequence directly as it's not the correct one for konsole and iTerm,
# and because we may want to change the cursor even though terminfo says we can't (tmux).
- if not tput Ss > /dev/null ^/dev/null
+ if not tput Ss >/dev/null ^/dev/null
# Whitelist tmux...
and not begin
set -q TMUX
# ...in a supporting term...
and begin set -q KONSOLE_PROFILE_NAME
or set -q ITERM_PROFILE
- or test "$VTE_VERSION" -gt 1910
+ or set -q VTE_VERSION # which version is already checked above
+ or test (string replace -r "XTerm\((\d+)\)" '$1' -- $XTERM_VERSION) -ge 280
end
# .. unless an unsupporting terminal has been started in tmux inside a supporting one
and begin string match -q "screen*" -- $TERM
@@ -31,13 +43,21 @@ function fish_vi_cursor -d 'Set cursor shape for different vi modes'
end
end
and not string match -q "konsole*" -- $TERM
- # Blacklist
or begin
- # vte-based terms set $TERM = xterm*, but only gained support relatively recently.
- set -q VTE_VERSION
- and test "$VTE_VERSION" -le 1910
+ # TERM = xterm is special because plenty of things claim to be it, but aren't fully compatible
+ # This includes old vte-terms (without $VTE_VERSION), old xterms (without $XTERM_VERSION or < 280)
+ # and maybe other stuff.
+ # This needs to be kept _at least_ as long as Ubuntu 14.04 is still a thing
+ # because that ships a gnome-terminal without support and without $VTE_VERSION.
+ string match -q 'xterm*' -- $TERM
+ and not begin set -q KONSOLE_PROFILE_NAME
+ or set -q ITERM_PROFILE
+ or set -q VTE_VERSION # which version is already checked above
+ # If $XTERM_VERSION is undefined, this will return 1 and print an error. Silence it.
+ or test (string replace -r "XTerm\((\d+)\)" '$1' -- $XTERM_VERSION) -ge 280 ^/dev/null
+ end
end
- or set -q INSIDE_EMACS
+
return
end
@@ -50,9 +70,11 @@ function fish_vi_cursor -d 'Set cursor shape for different vi modes'
switch "$terminal"
case auto
if set -q KONSOLE_PROFILE_NAME
- or set -q ITERM_PROFILE
set function __fish_cursor_konsole
set uses_echo 1
+ else if set -q ITERM_PROFILE
+ set function __fish_cursor_1337
+ set uses_echo 1
else
set function __fish_cursor_xterm
set uses_echo 1
@@ -68,7 +90,7 @@ function fish_vi_cursor -d 'Set cursor shape for different vi modes'
set -l tmux_prefix
set -l tmux_postfix
if set -q TMUX
- and set -q uses_echo[1]
+ and set -q uses_echo[1]
set tmux_prefix echo -ne "'\ePtmux;\e'"
set tmux_postfix echo -ne "'\e\\\\'"
end
diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish
index 1e03359df..51d8adebf 100644
--- a/share/functions/fish_vi_key_bindings.fish
+++ b/share/functions/fish_vi_key_bindings.fish
@@ -1,29 +1,41 @@
function fish_vi_key_bindings --description 'vi-like key bindings for fish'
+ if contains -- -h $argv
+ or contains -- --help $argv
+ echo "Sorry but this function doesn't support -h or --help"
+ return 1
+ end
+
# Erase all bindings if not explicitly requested otherwise to
# allow for hybrid bindings.
# This needs to be checked here because if we are called again
# via the variable handler the argument will be gone.
- if not contains -- $argv[1] --no-erase
- bind --erase --all
- else if set -q argv[1]
+ set -l rebind true
+ if test "$argv[1]" = "--no-erase"
+ set rebind false
set -e argv[1]
+ else
+ bind --erase --all # clear earlier bindings, if any
end
# Allow just calling this function to correctly set the bindings.
# Because it's a rather discoverable name, users will execute it
# and without this would then have subtly broken bindings.
if test "$fish_key_bindings" != "fish_vi_key_bindings"
- # Allow the user to set the variable universally
+ and test "$rebind" = "true"
+ # Allow the user to set the variable universally.
set -q fish_key_bindings
or set -g fish_key_bindings
- set fish_key_bindings fish_vi_key_bindings # This triggers the handler, which calls us again and ensures the user_key_bindings are executed
+ # This triggers the handler, which calls us again and ensures the user_key_bindings
+ # are executed.
+ set fish_key_bindings fish_vi_key_bindings
return
end
# The default escape timeout is 300ms. But for users of Vi bindings that can be slightly
# annoying when trying to switch to Vi "normal" mode. So set a shorter timeout in this case
# unless the user has explicitly set the delay.
- set -q fish_escape_delay_ms; or set -g fish_escape_delay_ms 100
+ set -q fish_escape_delay_ms
+ or set -g fish_escape_delay_ms 100
set -l init_mode insert
# These are only the special vi-style keys
@@ -46,7 +58,7 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish'
bind -M insert \r execute
bind -M insert \n execute
-
+
bind -M insert "" self-insert
# Add way to kill current command line while in insert mode.
@@ -98,17 +110,27 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish'
bind e forward-char forward-word backward-char
bind E forward-bigword backward-char
- bind x delete-char
- bind X backward-delete-char
+ # OS X SnowLeopard doesn't have these keys. Don't show an annoying error message.
+ # Vi/Vim doesn't support these keys in insert mode but that seems silly so we do so anyway.
+ bind -M insert -k home beginning-of-line 2>/dev/null
+ bind -M default -k home beginning-of-line 2>/dev/null
+ bind -M insert -k end end-of-line 2>/dev/null
+ bind -M default -k end end-of-line 2>/dev/null
- bind -k dc delete-char
+ bind -M default x delete-char
+ bind -M default X backward-delete-char
+ bind -M insert -k dc delete-char
+ bind -M default -k dc delete-char
# Backspace deletes a char in insert mode, but not in normal/default mode.
bind -M insert -k backspace backward-delete-char
bind -M default -k backspace backward-char
+ bind -M insert \ch backward-delete-char
+ bind -M default \ch backward-char
bind -M insert \x7f backward-delete-char
bind -M default \x7f backward-char
- bind \e\[3\;2~ backward-delete-char # Mavericks Terminal.app shift-delete
+ bind -M insert \e\[3\;2~ backward-delete-char # Mavericks Terminal.app shift-ctrl-delete
+ bind -M default \e\[3\;2~ backward-delete-char # Mavericks Terminal.app shift-ctrl-delete
bind dd kill-whole-line
bind D kill-line
diff --git a/share/functions/fish_vi_mode.fish b/share/functions/fish_vi_mode.fish
index 49023055e..8e2a92488 100644
--- a/share/functions/fish_vi_mode.fish
+++ b/share/functions/fish_vi_mode.fish
@@ -1,6 +1,6 @@
function fish_vi_mode
- echo 'The `fish_vi_mode` function is deprecated.' >&2
- echo 'Please switch to calling `fish_vi_key_bindings`.' >&2
- # Turn on vi keybindings
- set -g fish_key_bindings fish_vi_key_bindings
+ echo 'The `fish_vi_mode` function is deprecated.' >&2
+ echo 'Please switch to calling `fish_vi_key_bindings`.' >&2
+ # Turn on vi keybindings
+ set -g fish_key_bindings fish_vi_key_bindings
end
diff --git a/share/functions/funced.fish b/share/functions/funced.fish
index fd3060a7e..686c89b7c 100644
--- a/share/functions/funced.fish
+++ b/share/functions/funced.fish
@@ -48,9 +48,9 @@ function funced --description 'Edit function definition'
set -l init
switch $funcname
case '-*'
- set init function -- $funcname\n\nend
+ set init function -- $funcname\n\nend
case '*'
- set init function $funcname\n\nend
+ set init function $funcname\n\nend
end
# Break editor up to get its first command (i.e. discard flags)
@@ -63,13 +63,16 @@ function funced --description 'Edit function definition'
set editor fish
end
end
-
+
# If no editor is specified, use fish
if test -z "$editor"
set editor fish
end
- if begin; set -q interactive[1]; or test "$editor" = fish; end
+ if begin
+ set -q interactive[1]
+ or test "$editor" = fish
+ end
set -l IFS
if functions -q -- $funcname
# Shadow IFS here to avoid array splitting in command substitution
@@ -89,40 +92,41 @@ function funced --description 'Edit function definition'
# OSX mktemp is rather restricted - no suffix, no way to automatically use TMPDIR
# Create a directory so we can use a ".fish" suffix for the file - makes editors pick up that it's a fish file
- set -q TMPDIR; or set -l TMPDIR /tmp
+ set -q TMPDIR
+ or set -l TMPDIR /tmp
set -l tmpdir (mktemp -d $TMPDIR/fish.XXXXXX)
set -l tmpname $tmpdir/$funcname.fish
if functions -q -- $funcname
- functions -- $funcname > $tmpname
+ functions -- $funcname >$tmpname
else
- echo $init > $tmpname
+ echo $init >$tmpname
end
- # Repeatedly edit until it either parses successfully, or the user cancels
- # If the editor command itself fails, we assume the user cancelled or the file
- # could not be edited, and we do not try again
- while true
- if not eval $editor $tmpname
- _ "Editing failed or was cancelled"
- echo
- else
- if not source $tmpname
- # Failed to source the function file. Prompt to try again.
- echo # add a line between the parse error and the prompt
- set -l repeat
- set -l prompt (_ 'Edit the file again\? [Y/n]')
- while test -z "$repeat"
- read -p "echo $prompt\ " repeat
- end
- if not contains $repeat n N no NO No nO
- continue
- end
- _ "Cancelled function editing"
- echo
- end
+ # Repeatedly edit until it either parses successfully, or the user cancels
+ # If the editor command itself fails, we assume the user cancelled or the file
+ # could not be edited, and we do not try again
+ while true
+ if not eval $editor $tmpname
+ _ "Editing failed or was cancelled"
+ echo
+ else
+ if not source $tmpname
+ # Failed to source the function file. Prompt to try again.
+ echo # add a line between the parse error and the prompt
+ set -l repeat
+ set -l prompt (_ 'Edit the file again\? [Y/n]')
+ while test -z "$repeat"
+ read -p "echo $prompt\ " repeat
end
- break
+ if not contains $repeat n N no NO No nO
+ continue
+ end
+ _ "Cancelled function editing"
+ echo
+ end
end
+ break
+ end
set -l stat $status
rm $tmpname >/dev/null
and rmdir $tmpdir >/dev/null
diff --git a/share/functions/funcsave.fish b/share/functions/funcsave.fish
index bbf7a32a8..cbd186efe 100644
--- a/share/functions/funcsave.fish
+++ b/share/functions/funcsave.fish
@@ -1,43 +1,43 @@
function funcsave --description "Save the current definition of all specified functions to file"
- if count $argv >/dev/null
- switch $argv[1]
- case -h --h --he --hel --help
- __fish_print_help funcsave
- return 0
- end
- else
- printf (_ "%s: Expected function name\n") funcsave
- __fish_print_help funcsave
- return 1
- end
+ if count $argv >/dev/null
+ switch $argv[1]
+ case -h --h --he --hel --help
+ __fish_print_help funcsave
+ return 0
+ end
+ else
+ printf (_ "%s: Expected function name\n") funcsave
+ __fish_print_help funcsave
+ return 1
+ end
- set -l res 0
+ set -l res 0
- set -l configdir ~/.config
- if set -q XDG_CONFIG_HOME
- set configdir $XDG_CONFIG_HOME
- end
+ set -l configdir ~/.config
+ if set -q XDG_CONFIG_HOME
+ set configdir $XDG_CONFIG_HOME
+ end
- for i in $configdir $configdir/fish $configdir/fish/functions
- if not test -d $i
- if not command mkdir $i >/dev/null
- printf (_ "%s: Could not create configuration directory\n") funcsave
- return 1
- end
- end
- end
+ for i in $configdir $configdir/fish $configdir/fish/functions
+ if not test -d $i
+ if not command mkdir $i >/dev/null
+ printf (_ "%s: Could not create configuration directory\n") funcsave
+ return 1
+ end
+ end
+ end
- for i in $argv
- if functions -q -- $i
- functions -- $i > $configdir/fish/functions/$i.fish
- else
- printf (_ "%s: Unknown function '%s'\n") funcsave $i
- set res 1
- end
- end
+ for i in $argv
+ if functions -q -- $i
+ functions -- $i >$configdir/fish/functions/$i.fish
+ else
+ printf (_ "%s: Unknown function '%s'\n") funcsave $i
+ set res 1
+ end
+ end
- return $res
+ return $res
end
diff --git a/share/functions/grep.fish b/share/functions/grep.fish
index bedf18be7..0647494fa 100644
--- a/share/functions/grep.fish
+++ b/share/functions/grep.fish
@@ -3,7 +3,7 @@
#
if echo | command grep --color=auto "" >/dev/null 2>&1
- function grep
- command grep --color=auto $argv
- end
+ function grep
+ command grep --color=auto $argv
+ end
end
diff --git a/share/functions/help.fish b/share/functions/help.fish
index 23467a487..341f79aad 100644
--- a/share/functions/help.fish
+++ b/share/functions/help.fish
@@ -1,154 +1,151 @@
function help --description 'Show help for the fish shell'
-
- # Declare variables to set correct scope
- set -l fish_browser
- set -l fish_browser_bg
- set -l h syntax completion editor job-control todo bugs history killring help
- set h $h color prompt title variables builtin-overview changes expand
- set h $h expand-variable expand-home expand-brace expand-wildcard
- set -l help_topics $h expand-command-substitution expand-process
+ # Declare variables to set correct scope
+ set -l fish_browser
- # 'help -h' should launch 'help help'
- if count $argv >/dev/null
- switch $argv[1]
- case -h --h --he --hel --help
- __fish_print_help help
- return 0
- end
- end
+ set -l h syntax completion editor job-control todo bugs history killring help
+ set h $h color prompt title variables builtin-overview changes expand
+ set h $h expand-variable expand-home expand-brace expand-wildcard
+ set -l help_topics $h expand-command-substitution expand-process
- #
- # Find a suitable browser for viewing the help pages. This is needed
- # by the help function defined below.
- #
- set -l graphical_browsers htmlview x-www-browser firefox galeon mozilla konqueror epiphany opera netscape rekonq google-chrome chromium-browser
- set -l text_browsers htmlview www-browser links elinks lynx w3m
+ # 'help -h' should launch 'help help'
+ if count $argv >/dev/null
+ switch $argv[1]
+ case -h --h --he --hel --help
+ __fish_print_help help
+ return 0
+ end
+ end
- if type -q "$BROWSER"
- # User has manually set a preferred browser, so we respect that
- set fish_browser $BROWSER
+ #
+ # Find a suitable browser for viewing the help pages. This is needed
+ # by the help function defined below.
+ #
+ set -l graphical_browsers htmlview x-www-browser firefox galeon mozilla konqueror epiphany opera netscape rekonq google-chrome chromium-browser
- # If browser is known to be graphical, put into background
- if contains -- $BROWSER $graphical_browsers
- set fish_browser_bg 1
- end
- else
- # Check for a text-based browser.
- for i in $text_browsers
- if type -q -f $i
- set fish_browser $i
- break
- end
- end
+ if set -q fish_help_browser[1]
+ # User has set a fish-specific help browser. This overrides the
+ # browser that may be defined by $BROWSER. The fish_help_browser
+ # variable may be an array containing a browser name plus options.
+ set fish_browser $fish_help_browser
+ else
+ set -l text_browsers htmlview www-browser links elinks lynx w3m
- # If we are in a graphical environment, check if there is a graphical
- # browser to use instead.
- if test "$DISPLAY" -a \( "$XAUTHORITY" = "$HOME/.Xauthority" -o "$XAUTHORITY" = "" \)
- for i in $graphical_browsers
- if type -q -f $i
- set fish_browser $i
- set fish_browser_bg 1
- break
- end
- end
- end
+ if set -q BROWSER
+ # User has manually set a preferred browser, so we respect that
+ set fish_browser $BROWSER
+ else
+ # Check for a text-based browser.
+ for i in $text_browsers
+ if type -q -f $i
+ set fish_browser $i
+ break
+ end
+ end
- # If the OS appears to be Windows (graphical), try to use cygstart
- if type -q cygstart
- set fish_browser cygstart
- # If xdg-open is available, just use that
- else if type -q xdg-open
- set fish_browser xdg-open
- end
-
-
- # On OS X, we go through osascript by default
- if test (uname) = Darwin
- if type -q osascript
- set fish_browser osascript
- end
- end
+ # If we are in a graphical environment, check if there is a graphical
+ # browser to use instead.
+ if test "$DISPLAY" -a \( "$XAUTHORITY" = "$HOME/.Xauthority" -o "$XAUTHORITY" = "" \)
+ for i in $graphical_browsers
+ if type -q -f $i
+ set fish_browser $i
+ break
+ end
+ end
+ end
- end
+ # If the OS appears to be Windows (graphical), try to use cygstart
+ if type -q cygstart
+ set fish_browser cygstart
+ # If xdg-open is available, just use that
+ else if type -q xdg-open
+ set fish_browser xdg-open
+ end
- if test -z $fish_browser
- printf (_ '%s: Could not find a web browser.\n') help
- printf (_ 'Please set the variable $BROWSER to a suitable browser and try again.\n\n')
- return 1
- end
+ # On OS X, we go through osascript by default
+ if test (uname) = Darwin
+ if type -q osascript
+ set fish_browser osascript
+ end
+ end
+ end
+ end
- # In Cygwin, start the user-specified browser using cygstart
- if type -q cygstart
- if test $fish_browser != "cygstart"
- # Escaped quotes are necessary to work with spaces in the path
- # when the command is finally eval'd.
- set fish_browser cygstart \"$fish_browser\"
- end
- end
+ if not set -q fish_browser
+ printf (_ '%s: Could not find a web browser.\n') help
+ printf (_ 'Please set the variable $BROWSER or fish_help_browser and try again.\n\n')
+ return 1
+ end
- set -l fish_help_item $argv[1]
+ # In Cygwin, start the user-specified browser using cygstart
+ if type -q cygstart
+ if test $fish_browser != "cygstart"
+ # Escaped quotes are necessary to work with spaces in the path
+ # when the command is finally eval'd.
+ set fish_browser cygstart \"$fish_browser\"
+ end
+ end
- switch "$fish_help_item"
- case ""
- set fish_help_page index.html
- case "."
- set fish_help_page "commands.html\#source"
- case globbing
- set fish_help_page "index.html\#expand"
- case (__fish_print_commands)
- set fish_help_page "commands.html\#$fish_help_item"
- case $help_topics
- set fish_help_page "index.html\#$fish_help_item"
- case "*"
- if type -q -f $fish_help_item
- # Prefer to use fish's man pages, to avoid
- # the annoying useless "builtin" man page bash
- # installs on OS X
- set -l man_arg "$__fish_datadir/man/man1/$fish_help_item.1"
- if test -f "$man_arg"
- man $man_arg
- return
- end
- end
- set fish_help_page "index.html"
- end
-
- set -l page_url
- if test -f $__fish_help_dir/index.html
- # Help is installed, use it
- set page_url file://$__fish_help_dir/$fish_help_page
+ set -l fish_help_item $argv[1]
- # In Cygwin, we need to convert the base help dir to a Windows path before converting it to a file URL
- if type -q cygpath
- set page_url file://(cygpath -m $__fish_help_dir)/$fish_help_page
- end
- else
- # Go to the web. Only include one dot in the version string
- set -l version_string (echo $FISH_VERSION| cut -d . -f 1,2)
- set page_url http://fishshell.com/docs/$version_string/$fish_help_page
- end
-
- # OS X /usr/bin/open swallows fragments (anchors), so use osascript
- # Eval is just a cheesy way of removing the hash escaping
- if test "$fish_browser" = osascript
- osascript -e 'open location "'(eval echo $page_url)'"'
- return
- end
-
- if test $fish_browser_bg
+ switch "$fish_help_item"
+ case ""
+ set fish_help_page index.html
+ case "."
+ set fish_help_page "commands.html\#source"
+ case globbing
+ set fish_help_page "index.html\#expand"
+ case (__fish_print_commands)
+ set fish_help_page "commands.html\#$fish_help_item"
+ case $help_topics
+ set fish_help_page "index.html\#$fish_help_item"
+ case "*"
+ if type -q -f $fish_help_item
+ # Prefer to use fish's man pages, to avoid
+ # the annoying useless "builtin" man page bash
+ # installs on OS X
+ set -l man_arg "$__fish_datadir/man/man1/$fish_help_item.1"
+ if test -f "$man_arg"
+ man $man_arg
+ return
+ end
+ end
+ set fish_help_page "index.html"
+ end
- switch $fish_browser
- case 'htmlview' 'x-www-browser'
- printf (_ 'help: Help is being displayed in your default browser.\n')
+ set -l page_url
+ if test -f $__fish_help_dir/index.html
+ # Help is installed, use it
+ set page_url file://$__fish_help_dir/$fish_help_page
- case '*'
- printf (_ 'help: Help is being displayed in %s.\n') $fish_browser
+ # In Cygwin, we need to convert the base help dir to a Windows path before converting it to a file URL
+ if type -q cygpath
+ set page_url file://(cygpath -m $__fish_help_dir)/$fish_help_page
+ end
+ else
+ # Go to the web. Only include one dot in the version string
+ set -l version_string (echo $FISH_VERSION| cut -d . -f 1,2)
+ set page_url http://fishshell.com/docs/$version_string/$fish_help_page
+ end
- end
+ # OS X /usr/bin/open swallows fragments (anchors), so use osascript
+ # Eval is just a cheesy way of removing the hash escaping
+ if test "$fish_browser" = osascript
+ osascript -e 'open location "'(eval echo $page_url)'"'
+ return
+ end
- eval "$fish_browser $page_url &"
- else
- eval $fish_browser $page_url
- end
+
+ # If browser is known to be graphical, put into background
+ if contains -- $fish_browser[1] $graphical_browsers
+ switch $fish_browser[1]
+ case 'htmlview' 'x-www-browser'
+ printf (_ 'help: Help is being displayed in your default browser.\n')
+ case '*'
+ printf (_ 'help: Help is being displayed in %s.\n') $fish_browser[1]
+ end
+ eval "$fish_browser $page_url &"
+ else
+ eval $fish_browser $page_url
+ end
end
diff --git a/share/functions/hostname.fish b/share/functions/hostname.fish
index d4d2d2591..e45d984de 100644
--- a/share/functions/hostname.fish
+++ b/share/functions/hostname.fish
@@ -1,10 +1,10 @@
# Query for USERDOMAIN to shorten waiting times when OS isn't Windows.
set -q USERDOMAIN
and switch (uname)
-case 'CYGWIN_*'
- # Cygwin's hostname is broken when computer name contains Unicode
- # characters. This hack "fixes" hostname in Cygwin.
- function hostname --description "Show or set the system's host name"
- echo $USERDOMAIN
- end
+ case 'CYGWIN_*'
+ # Cygwin's hostname is broken when computer name contains Unicode
+ # characters. This hack "fixes" hostname in Cygwin.
+ function hostname --description "Show or set the system's host name"
+ echo $USERDOMAIN
+ end
end
diff --git a/share/functions/isatty.fish b/share/functions/isatty.fish
index df8199250..02282928a 100644
--- a/share/functions/isatty.fish
+++ b/share/functions/isatty.fish
@@ -1,30 +1,30 @@
function isatty -d "Tests if a file descriptor is a tty"
- set -l fd 0
- if count $argv >/dev/null
- switch $argv[1]
+ set -l fd 0
+ if count $argv >/dev/null
+ switch $argv[1]
- case -h --h --he --hel --help
- __fish_print_help isatty
- return 0
+ case -h --h --he --hel --help
+ __fish_print_help isatty
+ return 0
- case stdin ''
- set fd 0
+ case stdin ''
+ set fd 0
- case stdout
- set fd 1
+ case stdout
+ set fd 1
- case stderr
- set fd 2
+ case stderr
+ set fd 2
- case '*'
- set fd $argv[1]
+ case '*'
+ set fd $argv[1]
- end
- end
+ end
+ end
- # Use `command test` because `builtin test` doesn't open the regular fd's.
- # See https://github.com/fish-shell/fish-shell/issues/1228
- command test -t "$fd"
+ # Use `command test` because `builtin test` doesn't open the regular fd's.
+ # See https://github.com/fish-shell/fish-shell/issues/1228
+ command test -t "$fd"
end
diff --git a/share/functions/la.fish b/share/functions/la.fish
index 818aa11ec..355e1f83a 100644
--- a/share/functions/la.fish
+++ b/share/functions/la.fish
@@ -2,6 +2,6 @@
# These are very common and useful
#
function la --description "List contents of directory, including hidden files in directory using long format"
- ls -lah $argv
+ ls -lah $argv
end
diff --git a/share/functions/ll.fish b/share/functions/ll.fish
index d5aba9e57..e8230f4ec 100644
--- a/share/functions/ll.fish
+++ b/share/functions/ll.fish
@@ -2,5 +2,5 @@
# These are very common and useful
#
function ll --description "List contents of directory using long format"
- ls -lh $argv
+ ls -lh $argv
end
diff --git a/share/functions/ls.fish b/share/functions/ls.fish
index 2da4d6b81..7418195f4 100644
--- a/share/functions/ls.fish
+++ b/share/functions/ls.fish
@@ -1,36 +1,37 @@
#
-# Make ls use colors if we are on a system that supports this
+# Make ls use colors if we are on a system that supports that feature and writing to stdout.
#
+if command ls --version >/dev/null ^/dev/null
+ # This appears to be GNU ls.
+ function ls --description "List contents of directory"
+ set -l param --color=auto
+ if isatty 1
+ set param $param --indicator-style=classify
+ end
+ command ls $param $argv
+ end
-if command ls --version 1>/dev/null 2>/dev/null
- # This is GNU ls
- function ls --description "List contents of directory"
- set -l param --color=auto
- if isatty 1
- set param $param --indicator-style=classify
- end
- command ls $param $argv
- end
-
- if not set -q LS_COLORS
- if type -q -f dircolors
- set -l colorfile
- for file in ~/.dir_colors ~/.dircolors /etc/DIR_COLORS
- if test -f $file
- set colorfile $file
- break
- end
- end
- set -gx LS_COLORS (dircolors -c $colorfile | string replace -r 'setenv LS_COLORS \'(.*)\'' '$1')
- end
- end
-
-else
- # BSD, OS X and a few more support colors through the -G switch instead
- if command ls -G / 1>/dev/null 2>/dev/null
- function ls --description "List contents of directory"
- command ls -G $argv
- end
- end
+ if not set -q LS_COLORS
+ if command -s dircolors >/dev/null
+ set -l colorfile
+ for file in ~/.dir_colors ~/.dircolors /etc/DIR_COLORS
+ if test -f $file
+ set colorfile $file
+ break
+ end
+ end
+ # Here we rely on the legacy behavior of `dircolors -c` producing output suitable for
+ # csh in order to extract just the data we're interested in.
+ set -gx LS_COLORS (dircolors -c $colorfile | string split ' ')[3]
+ # The value should always be quoted but be conservative and check first.
+ if string match -qr '^([\'"]).*\1$' -- $LS_COLORS
+ set LS_COLORS (string match -r '^.(.*).$' $LS_COLORS)[2]
+ end
+ end
+ end
+else if command ls -G / >/dev/null ^/dev/null
+ # It looks like BSD, OS X and a few more which support colors through the -G switch instead.
+ function ls --description "List contents of directory"
+ command ls -G $argv
+ end
end
-
diff --git a/share/functions/man.fish b/share/functions/man.fish
index 25c81a4bb..c9d3ff7f0 100644
--- a/share/functions/man.fish
+++ b/share/functions/man.fish
@@ -1,23 +1,24 @@
function man --description "Format and display the on-line manual pages"
- # Work around the "builtin" manpage that everything symlinks to,
- # by prepending our fish datadir to man. This also ensures that man gives fish's
- # man pages priority, without having to put fish's bin directories first in $PATH
+ # Work around the "builtin" manpage that everything symlinks to,
+ # by prepending our fish datadir to man. This also ensures that man gives fish's
+ # man pages priority, without having to put fish's bin directories first in $PATH
- # Notice local but exported variable
- set -lx MANPATH (string join : $MANPATH)
- if test -z "$MANPATH"
- type -q manpath; and set MANPATH (command manpath)
- end
- set -l fish_manpath (dirname $__fish_datadir)/fish/man
- if test -d "$fish_manpath" -a -n "$MANPATH"
- set MANPATH "$fish_manpath":$MANPATH
+ # Notice local but exported variable
+ set -lx MANPATH (string join : $MANPATH)
+ if test -z "$MANPATH"
+ type -q manpath
+ and set MANPATH (command manpath)
+ end
+ set -l fish_manpath (dirname $__fish_datadir)/fish/man
+ if test -d "$fish_manpath" -a -n "$MANPATH"
+ set MANPATH "$fish_manpath":$MANPATH
- # Invoke man with this manpath, and we're done
- command man $argv
- return
- end
-
- # If fish's man pages could not be found, just invoke man normally
- command man $argv
+ # Invoke man with this manpath, and we're done
+ command man $argv
+ return
+ end
+
+ # If fish's man pages could not be found, just invoke man normally
+ command man $argv
end
diff --git a/share/functions/math.fish b/share/functions/math.fish
index ed638c695..584d1b27d 100644
--- a/share/functions/math.fish
+++ b/share/functions/math.fish
@@ -21,9 +21,15 @@ function math --description "Perform math calculations in bc"
return 2 # no arguments is an error
end
- # Stitch lines together manually. We can't rely on BC_LINE_LENGTH because some systems don't
- # have a new enough version of bc.
- set -l out (echo "scale=$scale; $argv" | bc | string replace -r '\\\\$' '' | string join '')
+ # Set BC_LINE_LENGTH to a ridiculously high number so it only uses one line for most results.
+ # We can't use 0 since some systems (including macOS) use an ancient bc that doesn't support it.
+ # We also can't count on this being recognized since some BSD systems don't recognize this env
+ # var at all and limit the line length to 70.
+ set -lx BC_LINE_LENGTH 500
+ set -l out (echo "scale=$scale; $argv" | bc)
+ if set -q out[2]
+ set out (string join '' (string replace \\ '' $out))
+ end
switch "$out"
case ''
# No output indicates an error occurred.
diff --git a/share/functions/nextd-or-forward-word.fish b/share/functions/nextd-or-forward-word.fish
index 037dd9946..9428b89e2 100644
--- a/share/functions/nextd-or-forward-word.fish
+++ b/share/functions/nextd-or-forward-word.fish
@@ -1,9 +1,9 @@
function nextd-or-forward-word
- set -l cmd (commandline)
- if test -z "$cmd"
- nextd
- commandline -f repaint
- else
- commandline -f forward-word
- end
+ set -l cmd (commandline)
+ if test -z "$cmd"
+ nextd
+ commandline -f repaint
+ else
+ commandline -f forward-word
+ end
end
diff --git a/share/functions/nextd.fish b/share/functions/nextd.fish
index 3f28d07ac..3a94e7d8e 100644
--- a/share/functions/nextd.fish
+++ b/share/functions/nextd.fish
@@ -1,18 +1,18 @@
function nextd --description "Move forward in the directory history"
- if count $argv >/dev/null
- switch $argv[1]
- case -h --h --he --hel --help
- __fish_print_help nextd
- return 0
- end
- end
+ if count $argv >/dev/null
+ switch $argv[1]
+ case -h --h --he --hel --help
+ __fish_print_help nextd
+ return 0
+ end
+ end
- # Parse arguments
- set -l show_hist 0
- set -l times 1
- if count $argv > /dev/null
+ # Parse arguments
+ set -l show_hist 0
+ set -l times 1
+ if count $argv >/dev/null
for i in (seq (count $argv))
switch $argv[$i]
case '-l' --l --li --lis --list
@@ -33,12 +33,13 @@ function nextd --description "Move forward in the directory history"
end
end
- # Traverse history
- set -l code 1
- if count $times > /dev/null
+ # Traverse history
+ set -l code 1
+ if count $times >/dev/null
for i in (seq $times)
# Try one step backward
- if __fish_move_last dirnext dirprev;
+ if __fish_move_last dirnext dirprev
+
# We consider it a success if we were able to do at least 1 step
# (low expectations are the key to happiness ;)
set code 0
@@ -48,16 +49,16 @@ function nextd --description "Move forward in the directory history"
end
end
- # Show history if needed
- if test $show_hist = 1
- dirh
- end
+ # Show history if needed
+ if test $show_hist = 1
+ dirh
+ end
- # Set direction for 'cd -'
- if test $code = 0 ^/dev/null
- set -g __fish_cd_direction prev
- end
+ # Set direction for 'cd -'
+ if test $code = 0 ^/dev/null
+ set -g __fish_cd_direction prev
+ end
- # All done
- return $code
+ # All done
+ return $code
end
diff --git a/share/functions/open.fish b/share/functions/open.fish
index 9eaa7eda6..6e606aeba 100644
--- a/share/functions/open.fish
+++ b/share/functions/open.fish
@@ -4,25 +4,25 @@
#
if not command -s open >/dev/null
- function open --description "Open file in default application"
- if count $argv >/dev/null
- switch $argv[1]
- case -h --h --he --hel --help
- __fish_print_help open
- return 0
- end
- end
+ function open --description "Open file in default application"
+ if count $argv >/dev/null
+ switch $argv[1]
+ case -h --h --he --hel --help
+ __fish_print_help open
+ return 0
+ end
+ end
- if type -q -f cygstart
- for i in $argv
- cygstart $i
- end
- else if type -q -f xdg-open
- for i in $argv
- xdg-open $i
- end
- else
- echo (_ 'No open utility found. Try installing "xdg-open" or "xdg-utils".')
- end
- end
+ if type -q -f cygstart
+ for i in $argv
+ cygstart $i
+ end
+ else if type -q -f xdg-open
+ for i in $argv
+ xdg-open $i
+ end
+ else
+ echo (_ 'No open utility found. Try installing "xdg-open" or "xdg-utils".')
+ end
+ end
end
diff --git a/share/functions/popd.fish b/share/functions/popd.fish
index 44a19593d..3a8287f5f 100644
--- a/share/functions/popd.fish
+++ b/share/functions/popd.fish
@@ -1,19 +1,19 @@
function popd --description "Pop directory from the stack and cd to it"
- if count $argv >/dev/null
- switch $argv[1]
- case -h --h --he --hel --help
- __fish_print_help popd
- return 0
- end
- end
+ if count $argv >/dev/null
+ switch $argv[1]
+ case -h --h --he --hel --help
+ __fish_print_help popd
+ return 0
+ end
+ end
- if test $dirstack[1]
- cd $dirstack[1]
- else
- printf (_ "%s: Directory stack is empty…\n") popd 1>&2
- return 1
- end
+ if test $dirstack[1]
+ cd $dirstack[1]
+ else
+ printf (_ "%s: Directory stack is empty…\n") popd 1>&2
+ return 1
+ end
- set -e dirstack[1]
+ set -e dirstack[1]
end
diff --git a/share/functions/prevd-or-backward-word.fish b/share/functions/prevd-or-backward-word.fish
index bbaca8aea..5f0c740ed 100644
--- a/share/functions/prevd-or-backward-word.fish
+++ b/share/functions/prevd-or-backward-word.fish
@@ -2,7 +2,7 @@ function prevd-or-backward-word
set -l cmd (commandline)
if test -z "$cmd"
prevd
- commandline -f repaint
+ commandline -f repaint
else
commandline -f backward-word
end
diff --git a/share/functions/prevd.fish b/share/functions/prevd.fish
index a1e2d3d30..3b538d884 100644
--- a/share/functions/prevd.fish
+++ b/share/functions/prevd.fish
@@ -1,18 +1,18 @@
function prevd --description "Move back in the directory history"
- if count $argv >/dev/null
- switch $argv[1]
- case -h --h --he --hel --help
- __fish_print_help prevd
- return 0
- end
- end
+ if count $argv >/dev/null
+ switch $argv[1]
+ case -h --h --he --hel --help
+ __fish_print_help prevd
+ return 0
+ end
+ end
- # Parse arguments
- set -l show_hist 0
- set -l times 1
- if count $argv > /dev/null
+ # Parse arguments
+ set -l show_hist 0
+ set -l times 1
+ if count $argv >/dev/null
for i in (seq (count $argv))
switch $argv[$i]
case '-l' --l --li --lis --list
@@ -31,14 +31,15 @@ function prevd --description "Move back in the directory history"
continue
end
end
- end
+ end
- # Traverse history
- set -l code 1
- if count $times > /dev/null
+ # Traverse history
+ set -l code 1
+ if count $times >/dev/null
for i in (seq $times)
# Try one step backward
- if __fish_move_last dirprev dirnext;
+ if __fish_move_last dirprev dirnext
+
# We consider it a success if we were able to do at least 1 step
# (low expectations are the key to happiness ;)
set code 0
@@ -48,16 +49,16 @@ function prevd --description "Move back in the directory history"
end
end
- # Show history if needed
- if test $show_hist = 1
- dirh
- end
+ # Show history if needed
+ if test $show_hist = 1
+ dirh
+ end
- # Set direction for 'cd -'
- if test $code = 0 ^/dev/null
- set -g __fish_cd_direction next
- end
+ # Set direction for 'cd -'
+ if test $code = 0 ^/dev/null
+ set -g __fish_cd_direction next
+ end
- # All done
- return $code
+ # All done
+ return $code
end
diff --git a/share/functions/prompt_pwd.fish b/share/functions/prompt_pwd.fish
index 96e9b2f33..71dfc461e 100644
--- a/share/functions/prompt_pwd.fish
+++ b/share/functions/prompt_pwd.fish
@@ -1,21 +1,23 @@
function prompt_pwd --description "Print the current working directory, shortened to fit the prompt"
- set -q argv[1]; and switch $argv[1]
- case -h --help
- __fish_print_help prompt_pwd
- return 0
- end
+ set -q argv[1]
+ and switch $argv[1]
+ case -h --help
+ __fish_print_help prompt_pwd
+ return 0
+ end
- # This allows overriding fish_prompt_pwd_dir_length from the outside (global or universal) without leaking it
- set -q fish_prompt_pwd_dir_length; or set -l fish_prompt_pwd_dir_length 1
+ # This allows overriding fish_prompt_pwd_dir_length from the outside (global or universal) without leaking it
+ set -q fish_prompt_pwd_dir_length
+ or set -l fish_prompt_pwd_dir_length 1
- # Replace $HOME with "~"
- set realhome ~
- set -l tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $PWD)
+ # Replace $HOME with "~"
+ set realhome ~
+ set -l tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $PWD)
- if [ $fish_prompt_pwd_dir_length -eq 0 ]
- echo $tmp
- else
- # Shorten to at most $fish_prompt_pwd_dir_length characters per directory
- string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' $tmp
- end
+ if [ $fish_prompt_pwd_dir_length -eq 0 ]
+ echo $tmp
+ else
+ # Shorten to at most $fish_prompt_pwd_dir_length characters per directory
+ string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' $tmp
+ end
end
diff --git a/share/functions/psub.fish b/share/functions/psub.fish
index 221045312..afed1788e 100644
--- a/share/functions/psub.fish
+++ b/share/functions/psub.fish
@@ -1,96 +1,99 @@
function psub --description "Read from stdin into a file and output the filename. Remove the file when the command that called psub exits."
- set -l dirname
- set -l filename
- set -l funcname
- set -l suffix
- set -l use_fifo 1
+ set -l dirname
+ set -l filename
+ set -l funcname
+ set -l suffix
+ set -l use_fifo 1
- while count $argv >/dev/null
+ while count $argv >/dev/null
- switch $argv[1]
- case -h --help
- __fish_print_help psub
- return 0
+ switch $argv[1]
+ case -h --help
+ __fish_print_help psub
+ return 0
- case -f --file
- set use_fifo 0
- set -e argv[1]
+ case -f --file
+ set use_fifo 0
+ set -e argv[1]
- case -s --suffix
- if not set -q argv[2]
- printf "psub: missing operand\n"
- return 1
- end
- set suffix $argv[2]
- set -e argv[1..2]
+ case -s --suffix
+ if not set -q argv[2]
+ printf "psub: missing operand\n"
+ return 1
+ end
+ set suffix $argv[2]
+ set -e argv[1..2]
- case --
- set -e argv[1]
- break
+ case --
+ set -e argv[1]
+ break
- case "-?" "--*"
- printf "psub: invalid option: '%s'\n" $argv[1]
- return 1
+ case "-?" "--*"
+ printf "psub: invalid option: '%s'\n" $argv[1]
+ return 1
- case "-*"
- # Ungroup short options: -hfs => -h -f -s
- set opts "-"(string sub -s 2 -- $argv[1] | string split "")
- set -e argv[1]
- set argv $opts $argv
+ case "-*"
+ # Ungroup short options: -hfs => -h -f -s
+ set opts "-"(string sub -s 2 -- $argv[1] | string split "")
+ set -e argv[1]
+ set argv $opts $argv
- case "*"
- printf "psub: extra operand: '%s'\n" $argv[1]
- return 1
- end
- end
+ case "*"
+ printf "psub: extra operand: '%s'\n" $argv[1]
+ return 1
+ end
+ end
- if not status --is-command-substitution
- echo psub: Not inside of command substitution >&2
- return 1
- end
+ if not status --is-command-substitution
+ echo psub: Not inside of command substitution >&2
+ return 1
+ end
- set -l TMPDIR $TMPDIR
- if test -z "$TMPDIR[1]"
- set TMPDIR /tmp
- end
+ set -l TMPDIR $TMPDIR
+ if test -z "$TMPDIR[1]"
+ set TMPDIR /tmp
+ end
- if test use_fifo = 1
- # Write output to pipe. This needs to be done in the background so
- # that the command substitution exits without needing to wait for
- # all the commands to exit
- set dirname (mktemp -d "$TMPDIR[1]"/.psub.XXXXXXXXXX); or return
- set filename $dirname/psub.fifo"$suffix"
- mkfifo $filename
- cat >$filename &
- else if test -z $suffix
- set filename (mktemp "$TMPDIR[1]"/.psub.XXXXXXXXXX)
- cat >$filename
- else
- set dirname (mktemp -d "$TMPDIR[1]"/.psub.XXXXXXXXXX)
- set filename $dirname/psub"$suffix"
- cat >$filename
- end
+ if test use_fifo = 1
+ # Write output to pipe. This needs to be done in the background so
+ # that the command substitution exits without needing to wait for
+ # all the commands to exit
+ set dirname (mktemp -d "$TMPDIR[1]"/.psub.XXXXXXXXXX)
+ or return
+ set filename $dirname/psub.fifo"$suffix"
+ mkfifo $filename
+ cat >$filename &
+ else if test -z $suffix
+ set filename (mktemp "$TMPDIR[1]"/.psub.XXXXXXXXXX)
+ cat >$filename
+ else
+ set dirname (mktemp -d "$TMPDIR[1]"/.psub.XXXXXXXXXX)
+ set filename $dirname/psub"$suffix"
+ cat >$filename
+ end
- # Write filename to stdout
- echo $filename
+ # Write filename to stdout
+ echo $filename
- # Find unique function name
- while true
- set funcname __fish_psub_(random);
- if not functions $funcname >/dev/null ^/dev/null
- break;
- end
- end
+ # Find unique function name
+ while true
+ set funcname __fish_psub_(random)
- # Make sure we erase file when caller exits
- function $funcname --on-job-exit caller --inherit-variable filename --inherit-variable dirname --inherit-variable funcname
- command rm $filename
- if count $dirname >/dev/null
- command rmdir $dirname
- end
- functions -e $funcname
- end
+ if not functions $funcname >/dev/null ^/dev/null
+ break
+
+ end
+ end
+
+ # Make sure we erase file when caller exits
+ function $funcname --on-job-exit caller --inherit-variable filename --inherit-variable dirname --inherit-variable funcname
+ command rm $filename
+ if count $dirname >/dev/null
+ command rmdir $dirname
+ end
+ functions -e $funcname
+ end
end
diff --git a/share/functions/pushd.fish b/share/functions/pushd.fish
index 64f213ee1..15e509be5 100644
--- a/share/functions/pushd.fish
+++ b/share/functions/pushd.fish
@@ -1,77 +1,77 @@
function pushd --description 'Push directory to stack'
- if count $argv >/dev/null
- # check for --help
- switch $argv[1]
- case -h --h --he --hel --help
- __fish_print_help pushd
- return 0
- end
+ if count $argv >/dev/null
+ # check for --help
+ switch $argv[1]
+ case -h --h --he --hel --help
+ __fish_print_help pushd
+ return 0
+ end
- # emulate bash by checking if argument of form +n or -n
- set -l rot_r
- set -l rot_l
- if string match -qr '^-[0-9]+$' -- $argv[1]
- set rot_r (string sub -s 2 -- $argv[1])
- else if string match -qr '^\+[0-9]+$' -- $argv[1]
- set rot_l (string sub -s 2 -- $argv[1])
- end
- end
+ # emulate bash by checking if argument of form +n or -n
+ set -l rot_r
+ set -l rot_l
+ if string match -qr '^-[0-9]+$' -- $argv[1]
+ set rot_r (string sub -s 2 -- $argv[1])
+ else if string match -qr '^\+[0-9]+$' -- $argv[1]
+ set rot_l (string sub -s 2 -- $argv[1])
+ end
+ end
- # emulate bash: an empty pushd should switch the top of dirs
- if test (count $argv) -eq 0
- # check that the stack isn't empty
- if test (count $dirstack) -eq 0
- echo "pushd: no other directory"
- return 1
- end
+ # emulate bash: an empty pushd should switch the top of dirs
+ if test (count $argv) -eq 0
+ # check that the stack isn't empty
+ if test (count $dirstack) -eq 0
+ echo "pushd: no other directory"
+ return 1
+ end
- # get the top two values of the dirs stack ... the first is pwd
- set -l top_dir (command pwd)
- set -l next_dir $dirstack[1]
+ # get the top two values of the dirs stack ... the first is pwd
+ set -l top_dir $PWD
+ set -l next_dir $dirstack[1]
- # alter the top of dirstack and move to directory
- set -g dirstack[1] $top_dir
- cd $next_dir
- return
- end
+ # alter the top of dirstack and move to directory
+ set -g dirstack[1] $top_dir
+ cd $next_dir
+ return
+ end
- # emulate bash: check for rotations
- if test -n "$rot_l" -o -n "$rot_r"
- # grab the current stack
- set -l stack (command pwd) $dirstack
+ # emulate bash: check for rotations
+ if test -n "$rot_l" -o -n "$rot_r"
+ # grab the current stack
+ set -l stack $PWD $dirstack
- # translate a right rotation to a left rotation
- if test -n "$rot_r"
- # check the rotation in range
- if test $rot_r -ge (count $stack)
- echo "pushd: -$rot_r: directory stack index out of range"
- return 1
- end
+ # translate a right rotation to a left rotation
+ if test -n "$rot_r"
+ # check the rotation in range
+ if test $rot_r -ge (count $stack)
+ echo "pushd: -$rot_r: directory stack index out of range"
+ return 1
+ end
- set rot_l (math (count $stack) - 1 - $rot_r)
- end
+ set rot_l (math (count $stack) - 1 - $rot_r)
+ end
- # check the rotation in range
- if test $rot_l -ge (count $stack)
- echo "pushd: +$rot_l: directory stack index out of range"
- return 1
- else
- # rotate stack unless rot_l is 0
- if test $rot_l -gt 0
- set stack $stack[(math $rot_l + 1)..(count $stack)] $stack[1..$rot_l]
- end
+ # check the rotation in range
+ if test $rot_l -ge (count $stack)
+ echo "pushd: +$rot_l: directory stack index out of range"
+ return 1
+ else
+ # rotate stack unless rot_l is 0
+ if test $rot_l -gt 0
+ set stack $stack[(math $rot_l + 1)..(count $stack)] $stack[1..$rot_l]
+ end
- # now reconstruct dirstack and change directory
- set -g dirstack $stack[2..(count $stack)]
- cd $stack[1]
- end
+ # now reconstruct dirstack and change directory
+ set -g dirstack $stack[2..(count $stack)]
+ cd $stack[1]
+ end
- # print the new stack
- dirs
- return
- end
+ # print the new stack
+ dirs
+ return
+ end
- # argv[1] is a directory
- set -g dirstack (command pwd) $dirstack
- cd $argv[1]
+ # argv[1] is a directory
+ set -g dirstack $PWD $dirstack
+ cd $argv[1]
end
diff --git a/share/functions/realpath.fish b/share/functions/realpath.fish
index e18cfd84b..f1f6743b6 100644
--- a/share/functions/realpath.fish
+++ b/share/functions/realpath.fish
@@ -1,50 +1,53 @@
# Provide a minimalist realpath implementation to help deal with platforms that may not provide it
-# as a command. If a realpath command is available simply pass all arguments thru to it. If not
-# fallback to alternative solutions.
+# as a command. If an external realpath or grealpath command is available simply pass all arguments
+# thru to it. If not fallback to our builtin.
-# The following is slightly subtle. The first time `realpath` is invoked by autoloading this script
-# will be read. If we see that there is an external realpath command we just return. That will cause
-# fish to run the external command. Or, if there is a grealpath, we alias it.
-# On the other hand, if an external command isn't found we provide a function that will facilitate
-# fallback behavion through our builtin.
+# The following is slightly subtle. We have to define a realpath function even if there is an
+# external command by that name. That's because if we don't the parser will select our builtin.
+# However, we only want our builtin if there is no external realpath command.
-if not command -s realpath >/dev/null
- # If there is a HomeBrew installed version of GNU realpath named grealpath use that.
- if command -s grealpath >/dev/null
- function realpath -w grealpath -d "print the resolved path [grealpath]"
- grealpath $argv
- end
- exit 0
+if command -s realpath >/dev/null
+ function realpath -w realpath -d "print the resolved path [command realpath]"
+ command realpath $argv
+ end
+ exit 0
+end
+
+# If there is a HomeBrew installed version of GNU realpath named grealpath use that.
+if command -s grealpath >/dev/null
+ function realpath -w grealpath -d "print the resolved path [command grealpath]"
+ command grealpath $argv
+ end
+ exit 0
+end
+
+function realpath -d "return an absolute path without symlinks"
+ if test -z "$argv"
+ printf "usage: %s%s%s %sfile%s …\n" (set_color -o) $_ (set_color normal) (set_color -u) (set_color normal)
+ echo " resolves files as absolute paths without symlinks"
+ return 1
end
- function realpath -d "return an absolute path without symlinks"
- if test -z "$argv"
- printf "usage: %s%s%s %sfile%s …\n" (set_color -o) $_ (set_color normal) (set_color -u) (set_color normal)
- echo " resolves files as absolute paths without symlinks"
- return 1
- end
+ # Loop over arguments - allow our realpath to work on more than one path per invocation
+ # like gnu/bsd realpath.
+ for arg in $argv
+ switch $arg
+ # These - no can do our realpath
+ case -s --strip --no-symlinks -z --zero --relative-base\* --relative-to\*
+ __fish_print_help realpath
+ return 2
- # Loop over arguments - allow our realpath to work on more than one path per invocation
- # like gnu/bsd realpath.
- for arg in $argv
- switch $arg
- # These - no can do our realpath
- case -s --strip --no-symlinks -z --zero --relative-base\* --relative-to\*
- __fish_print_help realpath
- return 2
-
- case -h --help --version
- __fish_print_help realpath
- return 0
+ case -h --help --version
+ __fish_print_help realpath
+ return 0
# Handle commands called with these arguments by dropping the arguments to protect
# realpath from them. There are no sure things here.
- case -e --canonicalize-existing --physical -P -q --quiet -m --canonicalize-missing
- continue
+ case -e --canonicalize-existing --physical -P -q --quiet -m --canonicalize-missing
+ continue
- case "*"
- builtin realpath $arg
- end
+ case "*"
+ builtin realpath $arg
end
end
end
diff --git a/share/functions/seq.fish b/share/functions/seq.fish
index 3675c9905..4d2af7541 100644
--- a/share/functions/seq.fish
+++ b/share/functions/seq.fish
@@ -2,47 +2,47 @@
# We can't call type here because that also calls seq
if not command -s seq >/dev/null
- # No seq command
- function seq --description "Print sequences of numbers"
- __fish_fallback_seq $argv
- end
+ # No seq command
+ function seq --description "Print sequences of numbers"
+ __fish_fallback_seq $argv
+ end
- function __fish_fallback_seq --description "Fallback implementation of the seq command"
-
- set -l from 1
- set -l step 1
- set -l to 1
-
- switch (count $argv)
- case 1
- set to $argv[1]
-
- case 2
- set from $argv[1]
- set to $argv[2]
-
- case 3
- set from $argv[1]
- set step $argv[2]
- set to $argv[3]
-
- case '*'
- printf (_ "%s: Expected 1, 2 or 3 arguments, got %d\n") seq (count $argv)
- return 1
-
- end
-
- for i in $from $step $to
- if not echo $i | grep -E '^-?[0-9]*([0-9]*|\.[0-9]+)$' >/dev/null
- printf (_ "%s: '%s' is not a number\n") seq $i
- return 1
- end
- end
-
- if [ $step -ge 0 ]
- echo "for( i=$from; i<=$to ; i+=$step ) i;" | bc
- else
- echo "for( i=$from; i>=$to ; i+=$step ) i;" | bc
- end
- end
+ function __fish_fallback_seq --description "Fallback implementation of the seq command"
+
+ set -l from 1
+ set -l step 1
+ set -l to 1
+
+ switch (count $argv)
+ case 1
+ set to $argv[1]
+
+ case 2
+ set from $argv[1]
+ set to $argv[2]
+
+ case 3
+ set from $argv[1]
+ set step $argv[2]
+ set to $argv[3]
+
+ case '*'
+ printf (_ "%s: Expected 1, 2 or 3 arguments, got %d\n") seq (count $argv)
+ return 1
+
+ end
+
+ for i in $from $step $to
+ if not echo $i | grep -E '^-?[0-9]*([0-9]*|\.[0-9]+)$' >/dev/null
+ printf (_ "%s: '%s' is not a number\n") seq $i
+ return 1
+ end
+ end
+
+ if [ $step -ge 0 ]
+ echo "for( i=$from; i<=$to ; i+=$step ) i;" | bc
+ else
+ echo "for( i=$from; i>=$to ; i+=$step ) i;" | bc
+ end
+ end
end
diff --git a/share/functions/setenv.fish b/share/functions/setenv.fish
index f32a17f6e..23cc94790 100644
--- a/share/functions/setenv.fish
+++ b/share/functions/setenv.fish
@@ -1,4 +1,4 @@
function setenv --description 'Set global variable. Alias for set -g, made for csh compatibility'
- set -gx $argv
+ set -gx $argv
end
diff --git a/share/functions/suspend.fish b/share/functions/suspend.fish
index af2ce5012..1d6e35a92 100644
--- a/share/functions/suspend.fish
+++ b/share/functions/suspend.fish
@@ -1,7 +1,8 @@
function suspend -d "Suspend the current shell."
- if contains -- $argv --help; or contains -- $argv -h
- __fish_print_help suspend
- and return 0
+ if contains -- $argv --help
+ or contains -- $argv -h
+ __fish_print_help suspend
+ and return 0
end
if begin contains -- $argv --force
or not status --is-interactive and not status --is-login
diff --git a/share/functions/trap.fish b/share/functions/trap.fish
index 094d37f1b..248d91f58 100644
--- a/share/functions/trap.fish
+++ b/share/functions/trap.fish
@@ -1,143 +1,143 @@
function __trap_translate_signal
- set upper (echo $argv[1]|tr a-z A-Z)
- string replace -r '^SIG' '' -- $upper
+ set upper (echo $argv[1]|tr a-z A-Z)
+ string replace -r '^SIG' '' -- $upper
end
function __trap_switch
- switch $argv[1]
- case EXIT
- echo --on-process-exit %self
+ switch $argv[1]
+ case EXIT
+ echo --on-process-exit %self
- case '*'
- echo --on-signal $argv[1]
- end
+ case '*'
+ echo --on-signal $argv[1]
+ end
end
function trap -d 'Perform an action when the shell receives a signal'
- set -l mode
- set -l cmd
- set -l sig
+ set -l mode
+ set -l cmd
+ set -l sig
- set -l options
- set -l longopt
- set -l shortopt lph
- if not getopt -T > /dev/null
- # GNU getopt
- set longopt print,help,list-signals
- set options -o $shortopt -l $longopt --
- # Verify options
- if not getopt -n type $options $argv >/dev/null
- return 1
- end
- else
- # Old getopt, used on OS X
- set options $shortopt
- # Verify options
- if not getopt $options $argv >/dev/null
- return 1
- end
- end
+ set -l options
+ set -l longopt
+ set -l shortopt lph
+ if not getopt -T >/dev/null
+ # GNU getopt
+ set longopt print,help,list-signals
+ set options -o $shortopt -l $longopt --
+ # Verify options
+ if not getopt -n type $options $argv >/dev/null
+ return 1
+ end
+ else
+ # Old getopt, used on OS X
+ set options $shortopt
+ # Verify options
+ if not getopt $options $argv >/dev/null
+ return 1
+ end
+ end
- # Do the real getopt invocation
- set -l tmp (getopt $options $argv)
+ # Do the real getopt invocation
+ set -l tmp (getopt $options $argv)
- # Break tmp up into an array
- set -l opt
- eval set opt $tmp
+ # Break tmp up into an array
+ set -l opt
+ eval set opt $tmp
- while count $opt >/dev/null
- switch $opt[1]
- case -h --help
- __fish_print_help trap
- return 0
+ while count $opt >/dev/null
+ switch $opt[1]
+ case -h --help
+ __fish_print_help trap
+ return 0
- case -p --print
- set mode print
+ case -p --print
+ set mode print
- case -l --list-signals
- set mode list
+ case -l --list-signals
+ set mode list
- case --
- set -e opt[1]
- break
+ case --
+ set -e opt[1]
+ break
- end
- set -e opt[1]
- end
+ end
+ set -e opt[1]
+ end
- if not count $mode >/dev/null
+ if not count $mode >/dev/null
- switch (count $opt)
+ switch (count $opt)
- case 0
- set mode print
+ case 0
+ set mode print
- case 1
- set mode clear
+ case 1
+ set mode clear
- case '*'
- if test opt[1] = -
- set -e opt[1]
- set mode clear
- else
- set mode set
- end
- end
- end
+ case '*'
+ if test opt[1] = -
+ set -e opt[1]
+ set mode clear
+ else
+ set mode set
+ end
+ end
+ end
- switch $mode
- case clear
- for i in $opt
- set sig (__trap_translate_signal $i)
- if test $sig
- functions -e __trap_handler_$sig
- end
- end
+ switch $mode
+ case clear
+ for i in $opt
+ set sig (__trap_translate_signal $i)
+ if test $sig
+ functions -e __trap_handler_$sig
+ end
+ end
- case set
- set -l cmd $opt[1]
- set -e opt[1]
+ case set
+ set -l cmd $opt[1]
+ set -e opt[1]
- for i in $opt
+ for i in $opt
- set -l sig (__trap_translate_signal $i)
- set sw (__trap_switch $sig)
+ set -l sig (__trap_translate_signal $i)
+ set sw (__trap_switch $sig)
- if test $sig
- eval "function __trap_handler_$sig $sw; $cmd; end"
- else
- return 1
- end
- end
+ if test $sig
+ eval "function __trap_handler_$sig $sw; $cmd; end"
+ else
+ return 1
+ end
+ end
- case print
- set -l names
+ case print
+ set -l names
- if count $opt >/dev/null
- set names $opt
- else
- set names (functions -na| string match "__trap_handler_*" | string replace '__trap_handler_' '')
- end
+ if count $opt >/dev/null
+ set names $opt
+ else
+ set names (functions -na| string match "__trap_handler_*" | string replace '__trap_handler_' '')
+ end
- for i in $names
+ for i in $names
- set sig (__trap_translate_signal $i)
+ set sig (__trap_translate_signal $i)
- if test sig
- functions __trap_handler_$i
- else
- return 1
- end
+ if test sig
+ functions __trap_handler_$i
+ else
+ return 1
+ end
- end
+ end
- case list
- kill -l
+ case list
+ kill -l
- end
+ end
end
diff --git a/share/functions/type.fish b/share/functions/type.fish
index ed113ea5d..ab0cd28b1 100644
--- a/share/functions/type.fish
+++ b/share/functions/type.fish
@@ -1,153 +1,156 @@
function type --description "Print the type of a command"
- # Initialize
- set -l res 1
- set -l mode normal
- set -l multi no
- set -l selection all
- set -l IFS \n\ \t
+ # Initialize
+ set -l res 1
+ set -l mode normal
+ set -l multi no
+ set -l selection all
+ set -l IFS \n\ \t
- # Parse options
- set -l names
- if test (count $argv) -gt 0
- for i in (seq (count $argv))
- set -l arg $argv[$i]
- set -l needbreak 0
- while test -n $arg
- set -l flag $arg
- set arg ''
- switch $flag
- case '--*'
- # do nothing; this just prevents it matching the next case
- case '-??*'
- # combined flags
- set -l IFS
- echo -n $flag | read __ flag arg
- set flag -$flag
- set arg -$arg
- end
- switch $flag
- case -t --type
- if test $mode != quiet
- set mode type
- end
+ # Parse options
+ set -l names
+ if test (count $argv) -gt 0
+ for i in (seq (count $argv))
+ set -l arg $argv[$i]
+ set -l needbreak 0
+ while test -n $arg
+ set -l flag $arg
+ set arg ''
+ switch $flag
+ case '--*'
+ # do nothing; this just prevents it matching the next case
+ case '-??*'
+ # combined flags
+ set -l IFS
+ echo -n $flag | read __ flag arg
+ set flag -$flag
+ set arg -$arg
+ end
+ switch $flag
+ case -t --type
+ if test $mode != quiet
+ set mode type
+ end
- case -p --path
- if test $mode != quiet
- set mode path
- end
+ case -p --path
+ if test $mode != quiet
+ set mode path
+ end
- case -P --force-path
- if test $mode != quiet
- set mode path
- end
- set selection files
+ case -P --force-path
+ if test $mode != quiet
+ set mode path
+ end
+ set selection files
- case -a --all
- set multi yes
+ case -a --all
+ set multi yes
- case -f --no-functions
- set selection files
+ case -f --no-functions
+ set selection files
- case -q --quiet
- set mode quiet
+ case -q --quiet
+ set mode quiet
- case -h --help
- __fish_print_help type
- return 0
+ case -h --help
+ __fish_print_help type
+ return 0
- case --
- set names $argv[$i..-1]
- set -e names[1]
- set needbreak 1
- break
+ case --
+ set names $argv[$i..-1]
+ set -e names[1]
+ set needbreak 1
+ break
- case '*'
- set names $argv[$i..-1]
- set needbreak 1
- break
- end
- end
- if test $needbreak -eq 1
- break
- end
- end
- end
+ case '*'
+ set names $argv[$i..-1]
+ set needbreak 1
+ break
+ end
+ end
+ if test $needbreak -eq 1
+ break
+ end
+ end
+ end
- # Check all possible types for the remaining arguments
- for i in $names
- # Found will be set to 1 if a match is found
- set -l found 0
+ # Check all possible types for the remaining arguments
+ for i in $names
+ # Found will be set to 1 if a match is found
+ set -l found 0
- if test $selection != files
+ if test $selection != files
- if functions -q -- $i
- set res 0
- set found 1
- switch $mode
- case normal
- printf (_ '%s is a function with definition\n') $i
- if isatty stdout
- functions $i | fish_indent --ansi
- else
- functions $i | fish_indent
- end
- case type
- echo (_ 'function')
- end
- if test $multi != yes
- continue
- end
- end
+ if functions -q -- $i
+ set res 0
+ set found 1
+ switch $mode
+ case normal
+ printf (_ '%s is a function with definition\n') $i
+ if isatty stdout
+ functions $i | fish_indent --ansi
+ else
+ functions $i | fish_indent
+ end
+ case type
+ echo (_ 'function')
+ end
+ if test $multi != yes
+ continue
+ end
+ end
- if contains -- $i (builtin -n)
+ if contains -- $i (builtin -n)
- set res 0
- set found 1
- switch $mode
- case normal
- printf (_ '%s is a builtin\n') $i
+ set res 0
+ set found 1
+ switch $mode
+ case normal
+ printf (_ '%s is a builtin\n') $i
- case type
- echo (_ 'builtin')
- end
- if test $multi != yes
- continue
- end
- end
+ case type
+ echo (_ 'builtin')
+ end
+ if test $multi != yes
+ continue
+ end
+ end
- end
+ end
- set -l paths
- if test $multi != yes
- set paths (command -s -- $i)
- else
- set paths (command which -a -- $i ^/dev/null)
- end
- for path in $paths
- set res 0
- set found 1
- switch $mode
- case normal
- printf (_ '%s is %s\n') $i $path
+ set -l paths
+ if test $multi != yes
+ set paths (command -s -- $i)
+ else
+ set paths (command which -a -- $i ^/dev/null)
+ end
+ for path in $paths
+ set res 0
+ set found 1
+ switch $mode
+ case normal
+ printf (_ '%s is %s\n') $i $path
- case type
- echo (_ 'file')
+ case type
+ echo (_ 'file')
- case path
- echo $path
- end
- if test $multi != yes
- continue
- end
- end
+ case path
+ echo $path
+ end
+ if test $multi != yes
+ continue
+ end
+ end
- if begin; test $found = 0; and test $mode != quiet; end
- printf (_ "%s: Could not find '%s'\n") type $i >&2
- end
+ if begin
+ test $found = 0
+ and test $mode != quiet
+ end
+ printf (_ "%s: Could not find '%s'\n") type $i >&2
+ end
- end
+ end
- return $res
+ return $res
end
diff --git a/share/functions/umask.fish b/share/functions/umask.fish
index a03c39b7e..4ad547818 100644
--- a/share/functions/umask.fish
+++ b/share/functions/umask.fish
@@ -1,216 +1,218 @@
function __fish_umask_parse -d "Internal umask function"
- # Test if already a valid octal mask, and pad it with zeros
- if echo $argv | __fish_sgrep -E '^0?[0-7]{1,3}$' >/dev/null
- set -l char_count (echo $argv| wc -c)
- for i in (seq (math 5 - $char_count)); set argv 0$argv; end
- echo $argv
- else
- # Test if argument really is a valid symbolic mask
- if not echo $argv | __fish_sgrep -E '^(((u|g|o|a|)(=|\+|-)|)(r|w|x)*)(,(((u|g|o|a|)(=|\+|-)|)(r|w|x)*))*$' >/dev/null
- printf (_ "%s: Invalid mask '%s'\n") umask $argv >&2
- return 1
- end
+ # Test if already a valid octal mask, and pad it with zeros
+ if echo $argv | __fish_sgrep -E '^0?[0-7]{1,3}$' >/dev/null
+ set -l char_count (echo $argv| wc -c)
+ for i in (seq (math 5 - $char_count))
+ set argv 0$argv
+ end
+ echo $argv
+ else
+ # Test if argument really is a valid symbolic mask
+ if not echo $argv | __fish_sgrep -E '^(((u|g|o|a|)(=|\+|-)|)(r|w|x)*)(,(((u|g|o|a|)(=|\+|-)|)(r|w|x)*))*$' >/dev/null
+ printf (_ "%s: Invalid mask '%s'\n") umask $argv >&2
+ return 1
+ end
- set -l implicit_all
+ set -l implicit_all
- # Insert inverted umask into res variable
+ # Insert inverted umask into res variable
- set -l mode
- set -l val
- set -l tmp $umask
- set -l res
+ set -l mode
+ set -l val
+ set -l tmp $umask
+ set -l res
- for i in 1 2 3
- set tmp (echo $tmp|cut -c 2-)
- set -l char_count (echo $tmp|cut -c 1)
- set res[$i] (math 7 - $char_count)
- end
+ for i in 1 2 3
+ set tmp (echo $tmp|cut -c 2-)
+ set -l char_count (echo $tmp|cut -c 1)
+ set res[$i] (math 7 - $char_count)
+ end
- set -l el (echo $argv|tr , \n)
- for i in $el
- switch $i
- case 'u*'
- set idx 1
- set i (echo $i| cut -c 2-)
+ set -l el (echo $argv|tr , \n)
+ for i in $el
+ switch $i
+ case 'u*'
+ set idx 1
+ set i (echo $i| cut -c 2-)
- case 'g*'
- set idx 2
- set i (echo $i| cut -c 2-)
+ case 'g*'
+ set idx 2
+ set i (echo $i| cut -c 2-)
- case 'o*'
- set idx 3
- set i (echo $i| cut -c 2-)
+ case 'o*'
+ set idx 3
+ set i (echo $i| cut -c 2-)
- case 'a*'
- set idx 1 2 3
- set i (echo $i| cut -c 2-)
+ case 'a*'
+ set idx 1 2 3
+ set i (echo $i| cut -c 2-)
- case '*'
- set implicit_all 1
- set idx 1 2 3
- end
+ case '*'
+ set implicit_all 1
+ set idx 1 2 3
+ end
- switch $i
- case '=*'
- set mode set
- set i (echo $i| cut -c 2-)
+ switch $i
+ case '=*'
+ set mode set
+ set i (echo $i| cut -c 2-)
- case '+*'
- set mode add
- set i (echo $i| cut -c 2-)
+ case '+*'
+ set mode add
+ set i (echo $i| cut -c 2-)
- case '-*'
- set mode remove
- set i (echo $i| cut -c 2-)
+ case '-*'
+ set mode remove
+ set i (echo $i| cut -c 2-)
- case '*'
- if not count $implicit_all >/dev/null
- printf (_ "%s: Invalid mask '%s'\n") umask $argv >&2
- return
- end
- set mode set
- end
+ case '*'
+ if not count $implicit_all >/dev/null
+ printf (_ "%s: Invalid mask '%s'\n") umask $argv >&2
+ return
+ end
+ set mode set
+ end
- if not echo $perm| __fish_sgrep -E '^(r|w|x)*$' >/dev/null
- printf (_ "%s: Invalid mask '%s'\n") umask $argv >&2
- return
- end
+ if not echo $perm | __fish_sgrep -E '^(r|w|x)*$' >/dev/null
+ printf (_ "%s: Invalid mask '%s'\n") umask $argv >&2
+ return
+ end
- set val 0
- if echo $i | __fish_sgrep 'r' >/dev/null
- set val 4
- end
- if echo $i | __fish_sgrep 'w' >/dev/null
- set val (math $val + 2)
- end
- if echo $i | __fish_sgrep 'x' >/dev/null
- set val (math $val + 1)
- end
+ set val 0
+ if echo $i | __fish_sgrep 'r' >/dev/null
+ set val 4
+ end
+ if echo $i | __fish_sgrep 'w' >/dev/null
+ set val (math $val + 2)
+ end
+ if echo $i | __fish_sgrep 'x' >/dev/null
+ set val (math $val + 1)
+ end
- for j in $idx
- switch $mode
- case set
- set res[$j] $val
+ for j in $idx
+ switch $mode
+ case set
+ set res[$j] $val
- case add
- set res[$j] (perl -e 'print( ( '$res[$j]'|'$val[$j]' )."\n" )')
+ case add
+ set res[$j] (perl -e 'print( ( '$res[$j]'|'$val[$j]' )."\n" )')
- case remove
- set res[$j] (perl -e 'print( ( (7-'$res[$j]')&'$val[$j]' )."\n" )')
- end
- end
- end
+ case remove
+ set res[$j] (perl -e 'print( ( (7-'$res[$j]')&'$val[$j]' )."\n" )')
+ end
+ end
+ end
- for i in 1 2 3
- set res[$i] (math 7 - $res[$i])
- end
- echo 0$res[1]$res[2]$res[3]
- end
+ for i in 1 2 3
+ set res[$i] (math 7 - $res[$i])
+ end
+ echo 0$res[1]$res[2]$res[3]
+ end
end
function __fish_umask_print_symbolic
- set -l res ""
- set -l letter a u g o
+ set -l res ""
+ set -l letter a u g o
- for i in 2 3 4
- set res $res,$letter[$i]=
- set val (echo $umask|cut -c $i)
+ for i in 2 3 4
+ set res $res,$letter[$i]=
+ set val (echo $umask|cut -c $i)
- if contains $val 0 1 2 3
- set res {$res}r
- end
+ if contains $val 0 1 2 3
+ set res {$res}r
+ end
- if contains $val 0 1 4 5
- set res {$res}w
- end
+ if contains $val 0 1 4 5
+ set res {$res}w
+ end
- if contains $val 0 2 4 6
- set res {$res}x
- end
+ if contains $val 0 2 4 6
+ set res {$res}x
+ end
- end
+ end
- echo $res|cut -c 2-
+ echo $res | cut -c 2-
end
function umask --description "Set default file permission mask"
- set -l as_command 0
- set -l symbolic 0
-
- set -l options
- set -l shortopt pSh
- if not getopt -T >/dev/null
- # GNU getopt
- set longopt -l as-command,symbolic,help
- set options -o $shortopt $longopt --
- # Verify options
- if not getopt -n umask $options $argv >/dev/null
- return 1
- end
- else
- # Old getopt, used on OS X
- set options $shortopt
- # Verify options
- if not getopt $options $argv >/dev/null
- return 1
- end
- end
+ set -l as_command 0
+ set -l symbolic 0
- set -l tmp (getopt $options $argv)
- eval set opt $tmp
+ set -l options
+ set -l shortopt pSh
+ if not getopt -T >/dev/null
+ # GNU getopt
+ set longopt -l as-command,symbolic,help
+ set options -o $shortopt $longopt --
+ # Verify options
+ if not getopt -n umask $options $argv >/dev/null
+ return 1
+ end
+ else
+ # Old getopt, used on OS X
+ set options $shortopt
+ # Verify options
+ if not getopt $options $argv >/dev/null
+ return 1
+ end
+ end
- while count $opt >/dev/null
+ set -l tmp (getopt $options $argv)
+ eval set opt $tmp
- switch $opt[1]
- case -h --help
- __fish_print_help umask
- return 0
+ while count $opt >/dev/null
- case -p --as-command
- set as_command 1
+ switch $opt[1]
+ case -h --help
+ __fish_print_help umask
+ return 0
- case -S --symbolic
- set symbolic 1
+ case -p --as-command
+ set as_command 1
- case --
- set -e opt[1]
- break
+ case -S --symbolic
+ set symbolic 1
- end
+ case --
+ set -e opt[1]
+ break
- set -e opt[1]
+ end
- end
+ set -e opt[1]
- switch (count $opt)
+ end
- case 0
- if not set -q umask
- set -g umask 113
- end
- if test $as_command -eq 1
- echo umask $umask
- else
- if test $symbolic -eq 1
- __fish_umask_print_symbolic $umask
- else
- echo $umask
- end
- end
+ switch (count $opt)
- case 1
- set -l parsed (__fish_umask_parse $opt)
- if test (count $parsed) -eq 1
- set -g umask $parsed
- return 0
- end
- return 1
+ case 0
+ if not set -q umask
+ set -g umask 113
+ end
+ if test $as_command -eq 1
+ echo umask $umask
+ else
+ if test $symbolic -eq 1
+ __fish_umask_print_symbolic $umask
+ else
+ echo $umask
+ end
+ end
- case '*'
- printf (_ '%s: Too many arguments\n') umask >&2
+ case 1
+ set -l parsed (__fish_umask_parse $opt)
+ if test (count $parsed) -eq 1
+ set -g umask $parsed
+ return 0
+ end
+ return 1
- end
+ case '*'
+ printf (_ '%s: Too many arguments\n') umask >&2
+
+ end
end
diff --git a/share/functions/up-or-search.fish b/share/functions/up-or-search.fish
index 98179ad7c..e0e64f6dd 100644
--- a/share/functions/up-or-search.fish
+++ b/share/functions/up-or-search.fish
@@ -1,26 +1,26 @@
function up-or-search -d "Depending on cursor position and current mode, either search backward or move up one line"
- # If we are already in search mode, continue
- if commandline --search-mode
- commandline -f history-search-backward
- return
- end
+ # If we are already in search mode, continue
+ if commandline --search-mode
+ commandline -f history-search-backward
+ return
+ end
- # If we are navigating the pager, then up always navigates
- if commandline --paging-mode
- commandline -f up-line
- return
- end
+ # If we are navigating the pager, then up always navigates
+ if commandline --paging-mode
+ commandline -f up-line
+ return
+ end
- # We are not already in search mode.
- # If we are on the top line, start search mode,
- # otherwise move up
- set lineno (commandline -L)
+ # We are not already in search mode.
+ # If we are on the top line, start search mode,
+ # otherwise move up
+ set lineno (commandline -L)
- switch $lineno
- case 1
- commandline -f history-search-backward
+ switch $lineno
+ case 1
+ commandline -f history-search-backward
- case '*'
- commandline -f up-line
- end
+ case '*'
+ commandline -f up-line
+ end
end
diff --git a/share/functions/vared.fish b/share/functions/vared.fish
index 97c233348..f14794df7 100644
--- a/share/functions/vared.fish
+++ b/share/functions/vared.fish
@@ -4,43 +4,43 @@
#
function vared --description "Edit variable value"
- if test (count $argv) = 1
- switch $argv
+ if test (count $argv) = 1
+ switch $argv
- case '-h' '--h' '--he' '--hel' '--help'
- __fish_print_help vared
- return 0
+ case '-h' '--h' '--he' '--hel' '--help'
+ __fish_print_help vared
+ return 0
- case '-*'
- printf (_ "%s: Unknown option %s\n") vared $argv
- return 1
+ case '-*'
+ printf (_ "%s: Unknown option %s\n") vared $argv
+ return 1
- case '*'
- if test (count $$argv ) -lt 2
- set -l init ''
- if test $$argv
- set init $$argv
- end
- set -l prompt 'set_color green; echo '$argv'; set_color normal; echo "> "'
- if read -p $prompt -c $init tmp
+ case '*'
+ if test (count $$argv ) -lt 2
+ set -l init ''
+ if test $$argv
+ set init $$argv
+ end
+ set -l prompt 'set_color green; echo '$argv'; set_color normal; echo "> "'
+ if read -p $prompt -c $init tmp
- # If variable already exists, do not add any
- # switches, so we don't change export rules. But
- # if it does not exist, we make the variable
- # global, so that it will not die when this
- # function dies
+ # If variable already exists, do not add any
+ # switches, so we don't change export rules. But
+ # if it does not exist, we make the variable
+ # global, so that it will not die when this
+ # function dies
- if test $$argv
- set $argv $tmp
- else
- set -g $argv $tmp
- end
- end
- else
- printf (_ '%s: %s is an array variable. Use %svared%s %s[n]%s to edit the n:th element of %s\n') vared $argv (set_color $fish_color_command; echo) (set_color $fish_color_normal; echo) $argv (set_color reset; echo) $argv
- end
- end
- else
- printf (_ '%s: Expected exactly one argument, got %s.\n\nSynopsis:\n\t%svared%s VARIABLE\n') vared (count $argv) (set_color $fish_color_command; echo) (set_color $fish_color_normal; echo)
- end
+ if test $$argv
+ set $argv $tmp
+ else
+ set -g $argv $tmp
+ end
+ end
+ else
+ printf (_ '%s: %s is an array variable. Use %svared%s %s[n]%s to edit the n:th element of %s\n') vared $argv (set_color $fish_color_command; echo) (set_color $fish_color_normal; echo) $argv (set_color normal; echo) $argv
+ end
+ end
+ else
+ printf (_ '%s: Expected exactly one argument, got %s.\n\nSynopsis:\n\t%svared%s VARIABLE\n') vared (count $argv) (set_color $fish_color_command; echo) (set_color $fish_color_normal; echo)
+ end
end
diff --git a/share/tools/create_manpage_completions.py b/share/tools/create_manpage_completions.py
index a65c057bb..e79744568 100755
--- a/share/tools/create_manpage_completions.py
+++ b/share/tools/create_manpage_completions.py
@@ -857,12 +857,26 @@ def parse_and_output_man_pages(paths, output_directory, show_progress):
def get_paths_from_manpath():
# Return all the paths to man(1) and man(8) files in the manpath
import subprocess, os
- proc = subprocess.Popen(['manpath'], stdout=subprocess.PIPE)
- manpath, err_data = proc.communicate()
+ # $MANPATH takes precedence, just like with `man` on the CLI.
+ if os.getenv("MANPATH"):
+ manpath = os.getenv("MANPATH")
+ else:
+ # Some systems have manpath, others have `man --path` (like Haiku).
+ # TODO: Deal with systems that have neither (OpenBSD)
+ for prog in [['manpath'], ['man', '--path']]:
+ try:
+ proc = subprocess.Popen(prog, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ except OSError: # Command does not exist, keep trying
+ continue
+ break # Command exists, use it.
+ manpath, err_data = proc.communicate()
parent_paths = manpath.decode().strip().split(':')
- if not parent_paths:
- sys.stderr.write("Unable to get the manpath (tried manpath)\n")
- sys.exit(-1)
+ if not parent_paths or proc.returncode > 0:
+ # HACK: Use some fallback in case we can't get anything else.
+ # `mandoc` does not provide `manpath` or `man --path` and $MANPATH might not be set, so just use the default for mandoc (minus /usr/X11R6/man, because that's not relevant).
+ # The alternative is reading its config file (/etc/man.conf)
+ sys.stderr.write("Unable to get the manpath, falling back to /usr/share/man:/usr/local/share/man. Please set $MANPATH if that is not correct.\n")
+ parent_paths = ["/usr/share/man", "/usr/local/share/man"]
result = []
for parent_path in parent_paths:
for section in ['man1', 'man6', 'man8']:
diff --git a/share/tools/web_config/fishconfig.css b/share/tools/web_config/fishconfig.css
index 9d6ef5eb5..1c9043732 100644
--- a/share/tools/web_config/fishconfig.css
+++ b/share/tools/web_config/fishconfig.css
@@ -117,7 +117,7 @@ body {
padding-top: 6px;
padding-bottom: 11px;
padding-left: 5px;
- padding-right: 22px;
+ padding-right: 22px;
font-size: 12pt;
/* Make our border overlap the detail, even if we're unselected (so it doesn't jump when selected) */
position: relative;
@@ -130,10 +130,10 @@ body {
border: 1px solid #555;
border-right: none;
background-color: #181818;
-
+
border-top-left-radius: 5;
border-bottom-left-radius: 5;
-
+
/* Pad one less than .master_element, to accomodate our border. */
padding-top: 5px;
padding-bottom: 10px;
@@ -231,7 +231,7 @@ body {
vertical-align: top;
overflow:hidden;
border-bottom: #444 dotted 1px;
- word-wrap: break-word;
+ word-wrap: break-word;
}
.history_delete {
diff --git a/share/tools/web_config/js/angular.js b/share/tools/web_config/js/angular.js
index 719bc648e..1d6b16487 100644
--- a/share/tools/web_config/js/angular.js
+++ b/share/tools/web_config/js/angular.js
@@ -203,7 +203,7 @@ function nextUid() {
/**
* Set or clear the hashkey for an object.
- * @param obj object
+ * @param obj object
* @param h the hashkey (!truthy to delete the hashkey)
*/
function setHashKey(obj, h) {
@@ -2154,21 +2154,21 @@ forEach({
}
}
return false;
- };
+ };
events[type] = [];
-
+
// Refer to jQuery's implementation of mouseenter & mouseleave
// Read about mouseenter and mouseleave:
// http://www.quirksmode.org/js/events_mouse.html#link8
- var eventmap = { mouseleave : "mouseout", mouseenter : "mouseover"}
+ var eventmap = { mouseleave : "mouseout", mouseenter : "mouseover"}
bindFn(element, eventmap[type], function(event) {
var ret, target = this, related = event.relatedTarget;
// For mousenter/leave call the handler if related is outside the target.
// NB: No relatedTarget if the mouse left/entered the browser window
if ( !related || (related !== target && !contains(target, related)) ){
handle(event, type);
- }
+ }
});
@@ -3472,18 +3472,18 @@ function $BrowserProvider(){
*
* @description
* Factory that constructs cache objects and gives access to them.
- *
+ *
*
- *
+ *
* var cache = $cacheFactory('cacheId');
* expect($cacheFactory.get('cacheId')).toBe(cache);
* expect($cacheFactory.get('noSuchCacheId')).not.toBeDefined();
*
* cache.put("key", "value");
* cache.put("another key", "another value");
- *
+ *
* expect(cache.info()).toEqual({id: 'cacheId', size: 2}); // Since we've specified no options on creation
- *
+ *
*
*
*
@@ -3660,10 +3660,10 @@ function $CacheFactoryProvider() {
* @name ng.$templateCache
*
* @description
- * The first time a template is used, it is loaded in the template cache for quick retrieval. You can
- * load templates directly into the cache in a `script` tag, or by consuming the `$templateCache`
+ * The first time a template is used, it is loaded in the template cache for quick retrieval. You can
+ * load templates directly into the cache in a `script` tag, or by consuming the `$templateCache`
* service directly.
- *
+ *
* Adding via the `script` tag:
*
*
@@ -3675,29 +3675,29 @@ function $CacheFactoryProvider() {
* ...
*
*
- *
- * **Note:** the `script` tag containing the template does not need to be included in the `head` of the document, but
+ *
+ * **Note:** the `script` tag containing the template does not need to be included in the `head` of the document, but
* it must be below the `ng-app` definition.
- *
+ *
* Adding via the $templateCache service:
- *
+ *
*
* var myApp = angular.module('myApp', []);
* myApp.run(function($templateCache) {
* $templateCache.put('templateId.html', 'This is the content of the template');
* });
*
- *
+ *
* To retrieve the template later, simply use it in your HTML:
*
*
*
- *
+ *
* or get it via Javascript:
*
* $templateCache.get('templateId.html')
*
- *
+ *
* See {@link ng.$cacheFactory $cacheFactory}.
*
*/
@@ -6902,25 +6902,25 @@ function $ParseProvider() {
* you can treat promises attached to a scope as if they were the resulting values.
* - Q has many more features than $q, but that comes at a cost of bytes. $q is tiny, but contains
* all the important functionality needed for common async tasks.
- *
+ *
* # Testing
- *
+ *
*
* it('should simulate promise', inject(function($q, $rootScope) {
* var deferred = $q.defer();
* var promise = deferred.promise;
* var resolvedValue;
- *
+ *
* promise.then(function(value) { resolvedValue = value; });
* expect(resolvedValue).toBeUndefined();
- *
+ *
* // Simulate resolving of promise
* deferred.resolve(123);
* // Note that the 'then' function does not get called synchronously.
* // This is because we want the promise API to always be async, whether or not
* // it got called synchronously or asynchronously.
* expect(resolvedValue).toBeUndefined();
- *
+ *
* // Propagate promise resolution to 'then' functions using $apply().
* $rootScope.$apply();
* expect(resolvedValue).toEqual(123);
@@ -8140,7 +8140,7 @@ function $RootScopeProvider(){
*
* @description
* Broadcasted when a scope and its children are being destroyed.
- *
+ *
* Note that, in AngularJS, there is also a `$destroy` jQuery event, which can be used to
* clean up DOM bindings before an element is removed from the DOM.
*/
@@ -8164,7 +8164,7 @@ function $RootScopeProvider(){
* Just before a scope is destroyed a `$destroy` event is broadcasted on this scope.
* Application code can register a `$destroy` event handler that will give it chance to
* perform any necessary cleanup.
- *
+ *
* Note that, in AngularJS, there is also a `$destroy` jQuery event, which can be used to
* clean up DOM bindings before an element is removed from the DOM.
*/
@@ -12677,8 +12677,8 @@ var ngValueDirective = function() {
* Typically, you don't use `ngBind` directly, but instead you use the double curly markup like
* `{{ expression }}` which is similar but less verbose.
*
- * It is preferrable to use `ngBind` instead of `{{ expression }}` when a template is momentarily
- * displayed by the browser in its raw state before Angular compiles it. Since `ngBind` is an
+ * It is preferrable to use `ngBind` instead of `{{ expression }}` when a template is momentarily
+ * displayed by the browser in its raw state before Angular compiles it. Since `ngBind` is an
* element attribute, it makes the bindings invisible to the user while the page is loading.
*
* An alternative solution to this problem would be using the
@@ -13174,20 +13174,20 @@ var ngControllerDirective = [function() {
* @element html
* @description
* Enables [CSP (Content Security Policy)](https://developer.mozilla.org/en/Security/CSP) support.
- *
+ *
* This is necessary when developing things like Google Chrome Extensions.
- *
+ *
* CSP forbids apps to use `eval` or `Function(string)` generated functions (among other things).
* For us to be compatible, we just need to implement the "getterFn" in $parse without violating
* any of these restrictions.
- *
+ *
* AngularJS uses `Function(string)` generated functions as a speed optimization. By applying `ngCsp`
* it is be possible to opt into the CSP compatible mode. When this mode is on AngularJS will
* evaluate all expressions up to 30% slower than in non-CSP mode, but no security violations will
* be raised.
- *
+ *
* In order to use this feature put `ngCsp` directive on the root element of the application.
- *
+ *
* @example
* This example shows how to apply the `ngCsp` directive to the `html` tag.
diff --git a/share/tools/web_config/js/app.js b/share/tools/web_config/js/app.js
index 6c5733898..0a31e89c2 100644
--- a/share/tools/web_config/js/app.js
+++ b/share/tools/web_config/js/app.js
@@ -41,9 +41,9 @@ fishconfig.config(function($httpProvider, $compileProvider) {
var global_error_element = null;
var showMessage = function(content) {
- global_error_element.text(content);
+ global_error_element.text(content);
};
-
+
$httpProvider.responseInterceptors.push(function($q) {
return function(promise) {
return promise.then(function(successResponse) {
diff --git a/share/tools/web_config/js/colorutils.js b/share/tools/web_config/js/colorutils.js
index 9222b3990..3b9fdebf0 100644
--- a/share/tools/web_config/js/colorutils.js
+++ b/share/tools/web_config/js/colorutils.js
@@ -74,7 +74,7 @@ function adjust_lightness(color_str, func) {
if (color_str[0] == '#') {
color_str = color_str.substring(1);
}
-
+
/* Hack to handle for example F00 */
if (color_str.length == 3) {
color_str = color_str[0] + color_str[0] + color_str[1] + color_str[1] + color_str[2] + color_str[2]
@@ -128,7 +128,7 @@ function text_color_for_color(color_str) {
return adjust_lightness(color_str, compute_constrast);
}
-function rgb_to_hsl(r, g, b) {
+function rgb_to_hsl(r, g, b) {
r /= 255, g /= 255, b /= 255;
var max = Math.max(r, g, b), min = Math.min(r, g, b);
var h, s, l = (max + min) / 2;
@@ -243,12 +243,12 @@ var color_scheme_fish_default = {
var TomorrowTheme = {
tomorrow_night: {'Background': '1d1f21', 'Current Line': '282a2e', 'Selection': '373b41', 'Foreground': 'c5c8c6', 'Comment': '969896', 'Red': 'cc6666', 'Orange': 'de935f', 'Yellow': 'f0c674', 'Green': 'b5bd68', 'Aqua': '8abeb7', 'Blue': '81a2be', 'Purple': 'b294bb'
},
-
+
tomorrow: {'Background': 'ffffff', 'Current Line': 'efefef', 'Selection': 'd6d6d6', 'Foreground': '4d4d4c', 'Comment': '8e908c', 'Red': 'c82829', 'Orange': 'f5871f', 'Yellow': 'eab700', 'Green': '718c00', 'Aqua': '3e999f', 'Blue': '4271ae', 'Purple': '8959a8'
},
-
+
tomorrow_night_bright: {'Background': '000000', 'Current Line': '2a2a2a', 'Selection': '424242', 'Foreground': 'eaeaea', 'Comment': '969896', 'Red': 'd54e53', 'Orange': 'e78c45', 'Yellow': 'e7c547', 'Green': 'b9ca4a', 'Aqua': '70c0b1', 'Blue': '7aa6da', 'Purple': 'c397d8'},
-
+
apply: function(theme, receiver){
receiver['autosuggestion'] = theme['Comment']
receiver['command'] = theme['Purple']
@@ -258,7 +258,7 @@ var TomorrowTheme = {
receiver['param'] = theme['Blue']
receiver['quote'] = theme['Green']
receiver['redirection'] = theme['Aqua']
-
+
receiver['colors'] = []
for (var key in theme) receiver['colors'].push(theme[key])
}
@@ -273,9 +273,9 @@ var solarized = {
var color_scheme_solarized_light = {
name: "Solarized Light",
colors: dict_values(solarized),
-
+
preferred_background: '#' + solarized.base3,
-
+
autosuggestion: solarized.base1,
command: solarized.base01,
comment: solarized.base1,
@@ -284,7 +284,7 @@ var color_scheme_solarized_light = {
param: solarized.base00,
quote: solarized.base0,
redirection: solarized.violet,
-
+
url: 'http://ethanschoonover.com/solarized'
};
@@ -292,7 +292,7 @@ var color_scheme_solarized_dark = {
name: "Solarized Dark",
colors: dict_values(solarized),
preferred_background: '#' + solarized.base03,
-
+
autosuggestion: solarized.base01,
command: solarized.base1,
comment: solarized.base01,
@@ -301,7 +301,7 @@ var color_scheme_solarized_dark = {
param: solarized.base0,
quote: solarized.base00,
redirection: solarized.violet,
-
+
url: 'http://ethanschoonover.com/solarized'
};
@@ -332,15 +332,15 @@ function construct_scheme_analogous(label, background, color_list) {
name: label,
preferred_background: background,
colors: color_list,
-
+
command: color_list[0],
quote: color_list[6],
param: color_list[5],
autosuggestion: color_list[4],
-
+
error: color_list[9],
comment: color_list[12],
-
+
end: color_list[10],
redirection: color_list[11]
};
@@ -351,16 +351,16 @@ function construct_scheme_triad(label, background, color_list) {
name: label,
preferred_background: background,
colors: color_list,
-
+
command: color_list[0],
quote: color_list[2],
param: color_list[1],
autosuggestion: color_list[3],
redirection: color_list[4],
-
+
error: color_list[8],
comment: color_list[10],
-
+
end: color_list[7],
};
}
@@ -370,30 +370,30 @@ function construct_scheme_complementary(label, background, color_list) {
name: label,
preferred_background: background,
colors: color_list,
-
+
command: color_list[0],
quote: color_list[4],
param: color_list[3],
autosuggestion: color_list[2],
redirection: color_list[6],
-
+
error: color_list[5],
comment: color_list[8],
-
+
end: color_list[9],
};
}
function construct_color_scheme_mono(label, background, from_end) {
var mono_colors = ['000000', '121212', '1c1c1c', '262626', '303030', '3a3a3a', '444444', '4e4e4e', '585858', '5f5f5f', '626262', '6c6c6c', '767676', '808080', '878787', '8a8a8a', '949494', '9e9e9e', 'a8a8a8', 'afafaf', 'b2b2b2', 'bcbcbc', 'c6c6c6', 'd0d0d0', 'd7d7d7', 'dadada', 'e4e4e4', 'eeeeee', 'ffffff'];
-
+
if (from_end) mono_colors.reverse();
-
+
return {
name: label,
preferred_background: background,
colors: mono_colors,
-
+
autosuggestion: '777777',
command: mono_colors[0],
comment: mono_colors[7],
@@ -407,21 +407,21 @@ function construct_color_scheme_mono(label, background, from_end) {
var additional_color_schemes = [
construct_scheme_analogous('Snow Day', 'white', ['164CC9', '325197', '072D83', '4C7AE4', '7596E4', '4319CC', '4C3499', '260885', '724EE5', '9177E5', '02BDBD', '248E8E', '007B7B', '39DEDE', '65DEDE']),
-
+
construct_scheme_analogous('Lava', '#232323', ['FF9400', 'BF8330', 'A66000', 'FFAE40', 'FFC473', 'FFC000', 'BF9C30', 'A67D00', 'FFD040', 'FFDD73', 'FF4C00', 'BF5B30', 'A63100', 'FF7940', 'FF9D73']),
-
+
construct_scheme_analogous('Seaweed', '#232323', ['00BF32', '248F40', '007C21', '38DF64', '64DF85', '04819E', '206676', '015367', '38B2CE', '60B9CE', '8EEB00', '7CB02C', '5C9900', 'ACF53D', 'C0F56E']),
-
+
construct_scheme_triad('Fairground', '#003', ['0772A1', '225E79', '024A68', '3BA3D0', '63AFD0', 'D9005B', 'A3295C', '8D003B', 'EC3B86', 'EC6AA1', 'FFE100', 'BFAE30', 'A69200', 'FFE840', 'FFEE73']),
-
+
construct_scheme_complementary('Bay Cruise', 'black', ['009999', '1D7373', '006363', '33CCCC', '5CCCCC', 'FF7400', 'BF7130', 'A64B00', 'FF9640', 'FFB273']),
{
'name': 'Old School',
'preferred_background': 'black',
-
+
colors: ['00FF00', '30BE30', '00A400', '44FF44', '7BFF7B', 'FF0000', 'BE3030', 'A40000', 'FF7B7B', '777777', 'CCCCCC'],
-
+
autosuggestion: '777777',
command: '00FF00',
comment: '30BE30',
@@ -435,9 +435,9 @@ var additional_color_schemes = [
{
'name': 'Just a Touch',
'preferred_background': 'black',
-
+
colors: ['B0B0B0', '969696', '789276', 'F4F4F4', 'A0A0F0', '666A80', 'F0F0F0', 'D7D7D7', 'B7B7B7', 'FFA779', 'FAFAFA'],
-
+
autosuggestion: '9C9C9C',
command: 'F4F4F4',
comment: 'B0B0B0',
@@ -448,6 +448,22 @@ var additional_color_schemes = [
redirection: 'FAFAFA'
},
+{
+ 'name': 'Dracula',
+ 'preferred_background': '#282a36',
+
+ colors: ['282A36', '44475A', '44475A', 'F8F8F2', '6272A4', '8BE9FD', '50FA7B', 'FFB86C', 'FF79C6', 'BD93F9', 'FF5555', 'F1FA8C'],
+
+ autosuggestion: 'BD93F9',
+ command: 'F8F8F2',
+ comment: '6272A4',
+ end: '50FA7B',
+ error: 'FFB86C',
+ param: 'FF79C6',
+ quote: 'F1FA8C',
+ redirection: '8BE9FD'
+},
+
construct_color_scheme_mono('Mono Lace', 'white', false),
construct_color_scheme_mono('Mono Smoke', 'black', true)
];
diff --git a/share/tools/web_config/js/controllers.js b/share/tools/web_config/js/controllers.js
index 73985b7a5..76d3aaab4 100644
--- a/share/tools/web_config/js/controllers.js
+++ b/share/tools/web_config/js/controllers.js
@@ -22,7 +22,7 @@ controllers.controller("colorsController", function($scope, $http) {
$scope.colorArraysArray = $scope.getColorArraysArray();
//TODO: Save button should be shown only when colors are changed
$scope.showSaveButton = true;
-
+
$scope.noteThemeChanged();
}
@@ -31,7 +31,7 @@ controllers.controller("colorsController", function($scope, $http) {
}
$scope.text_color_for_color = text_color_for_color;
-
+
$scope.border_color_for_color = border_color_for_color;
$scope.getColorArraysArray = function() {
@@ -42,7 +42,7 @@ controllers.controller("colorsController", function($scope, $http) {
result = get_colors_as_nested_array(term_256_colors, 32);
return result;
}
-
+
$scope.beginCustomizationWithSetting = function(setting) {
if (! $scope.customizationActive) {
$scope.customizationActive = true;
@@ -51,14 +51,14 @@ controllers.controller("colorsController", function($scope, $http) {
$scope.csUserVisibleTitle = user_visible_title_for_setting_name(setting);
}
}
-
+
$scope.selectColorSetting = function(name) {
$scope.selectedColorSetting = name;
$scope.csEditingType = $scope.customizationActive ? name : '';
$scope.csUserVisibleTitle = user_visible_title_for_setting_name(name);
$scope.beginCustomizationWithSetting(name);
}
-
+
$scope.toggleCustomizationActive = function() {
if (! $scope.customizationActive) {
$scope.beginCustomizationWithSetting($scope.selectedColorSetting || 'command');
@@ -93,7 +93,7 @@ controllers.controller("colorsController", function($scope, $http) {
})};
$scope.saveThemeButtonTitle = "Set Theme";
-
+
$scope.noteThemeChanged = function() {
$scope.saveThemeButtonTitle = "Set Theme";
}
@@ -135,7 +135,7 @@ controllers.controller("promptController", function($scope, $http) {
$scope.selectPrompt = function(prompt) {
$scope.selectedPrompt= prompt;
-
+
$scope.savePromptButtonTitle = "Set Prompt";
}
@@ -163,7 +163,7 @@ controllers.controller("promptController", function($scope, $http) {
controllers.controller("functionsController", function($scope, $http) {
$scope.selectedFunction = null;
- $scope.functionDefinition = "";
+ $scope.functionDefinition = "";
$scope.selectFunction = function(fun) {
$scope.selectedFunction = fun;
diff --git a/share/tools/web_config/sample_prompts/acidhub.fish b/share/tools/web_config/sample_prompts/acidhub.fish
index 08fd47fe7..24d675396 100644
--- a/share/tools/web_config/sample_prompts/acidhub.fish
+++ b/share/tools/web_config/sample_prompts/acidhub.fish
@@ -12,7 +12,7 @@ function fish_prompt -d "Write out the prompt"
if [ (_git_branch_name) ]
set -l git_branch (set_color -o blue)(_git_branch_name)
if [ (_is_git_dirty) ]
- for i in (git branch -qv --no-color | string match -r \* | cut -d' ' -f4- | cut -d] -f1 | tr , \n)\
+ for i in (git branch -qv --no-color | string match -r '\*' | cut -d' ' -f4- | cut -d] -f1 | tr , \n)\
(git status --porcelain | cut -c 1-2 | uniq)
switch $i
case "*[ahead *"
diff --git a/share/tools/web_config/webconfig.py b/share/tools/web_config/webconfig.py
index eb5dc5c51..fcf79e0af 100755
--- a/share/tools/web_config/webconfig.py
+++ b/share/tools/web_config/webconfig.py
@@ -1,50 +1,49 @@
#!/usr/bin/env python
from __future__ import unicode_literals
-# Whether we're Python 2
-import sys
+from __future__ import print_function
+import binascii
+import cgi
+import glob
import multiprocessing.pool
-import os
import operator
+import os
+import random
+import re
+import select
import socket
+import string
+import subprocess
+import sys
+import webbrowser
+
+FISH_BIN_PATH = False # will be set later
IS_PY2 = sys.version_info[0] == 2
if IS_PY2:
import SimpleHTTPServer
import SocketServer
from urlparse import parse_qs
-
else:
import http.server as SimpleHTTPServer
import socketserver as SocketServer
from urllib.parse import parse_qs
-# Check to see if IPv6 is enabled in the kernel
-HAS_IPV6 = True
-try:
- s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
- s.close()
-except:
- HAS_IPV6 = False
-
# Disable CLI web browsers
term = os.environ.pop('TERM', None)
-import webbrowser
if term:
os.environ['TERM'] = term
-import subprocess
-import re, socket, cgi, select, time, glob, random, string, binascii
try:
import json
except ImportError:
import simplejson as json
-FISH_BIN_PATH = False # will be set later
+
def run_fish_cmd(text):
- from subprocess import PIPE
- # ensure that fish is using UTF-8
- ctype = os.environ.get("LC_ALL", os.environ.get("LC_CTYPE", os.environ.get("LANG")))
+ # Ensure that fish is using UTF-8.
+ ctype = os.environ.get("LC_ALL", os.environ.get("LC_CTYPE",
+ os.environ.get("LANG")))
env = None
if ctype is None or re.search(r"\.utf-?8$", ctype, flags=re.I) is None:
# override LC_CTYPE with en_US.UTF-8
@@ -52,11 +51,14 @@ def run_fish_cmd(text):
# Fish makes the same assumption in config.fish
env = os.environ.copy()
env.update(LC_CTYPE="en_US.UTF-8", LANG="en_US.UTF-8")
- p = subprocess.Popen([FISH_BIN_PATH], stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env)
+ p = subprocess.Popen([FISH_BIN_PATH], stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ env=env)
out, err = p.communicate(text.encode('utf-8'))
out = out.decode('utf-8', 'replace')
err = err.decode('utf-8', 'replace')
- return(out, err)
+ return out, err
+
def escape_fish_cmd(text):
# Replace one backslash with two, and single quotes with backslash-quote
@@ -64,56 +66,52 @@ def escape_fish_cmd(text):
return "'" + escaped + "'"
named_colors = {
- 'black' : '000000',
- 'red' : '800000',
- 'green' : '008000',
- 'brown' : '725000',
- 'yellow' : '808000',
- 'blue' : '000080',
- 'magenta' : '800080',
- 'purple' : '800080',
- 'cyan' : '008080',
- 'grey' : 'e5e5e5',
- 'brgrey' : '555555',
- 'white' : 'c0c0c0',
- 'brblack' : '808080',
- 'brred' : 'ff0000',
- 'brgreen' : '00ff00',
- 'brbrown' : 'ffff00',
- 'bryellow' : 'ffff00',
- 'brblue' : '0000ff',
- 'brmagenta' : 'ff00ff',
- 'brpurple' : 'ff00ff',
- 'brcyan' : '00ffff',
- 'brwhite' : 'ffffff'
+ 'black': '000000', 'red': '800000', 'green': '008000', 'brown': '725000',
+ 'yellow': '808000', 'blue': '000080', 'magenta': '800080',
+ 'purple': '800080', 'cyan': '008080', 'grey': 'e5e5e5', 'brgrey': '555555',
+ 'white': 'c0c0c0', 'brblack': '808080', 'brred': 'ff0000',
+ 'brgreen': '00ff00', 'brbrown': 'ffff00', 'bryellow': 'ffff00',
+ 'brblue': '0000ff', 'brmagenta': 'ff00ff', 'brpurple': 'ff00ff',
+ 'brcyan': '00ffff', 'brwhite': 'ffffff'
}
bindings_blacklist = set(["self-insert", "'begin;end'"])
+
def parse_one_color(comp):
""" A basic function to parse a single color value like 'FFA000' """
if comp in named_colors:
# Named color
return named_colors[comp]
- elif re.match(r"[0-9a-fA-F]{3}", comp) is not None or re.match(r"[0-9a-fA-F]{6}", comp) is not None:
+ elif (re.match(r"[0-9a-fA-F]{3}", comp) is not None or
+ re.match(r"[0-9a-fA-F]{6}", comp) is not None):
# Hex color
return comp
else:
# Unknown
return ''
+
def better_color(c1, c2):
""" Indicate which color is "better", i.e. prefer term256 colors """
- if not c2: return c1
- if not c1: return c2
- if c1 == 'normal': return c2
- if c2 == 'normal': return c1
- if c2 in named_colors: return c1
- if c1 in named_colors: return c2
+ if not c2:
+ return c1
+ if not c1:
+ return c2
+ if c1 == 'normal':
+ return c2
+ if c2 == 'normal':
+ return c1
+ if c2 in named_colors:
+ return c1
+ if c1 in named_colors:
+ return c2
return c1
+
def parse_color(color_str):
- """ A basic function to parse a color string, for example, 'red' '--bold' """
+ """ A basic function to parse a color string, for example, 'red' '--bold'.
+ """
comps = color_str.split(' ')
color = 'normal'
background_color = ''
@@ -127,21 +125,69 @@ def parse_color(color_str):
underline = True
elif comp.startswith('--background='):
# Background color
- background_color = better_color(background_color, parse_one_color(comp[len('--background='):]))
+ background_color = better_color(
+ background_color, parse_one_color(comp[len('--background='):]))
else:
# Regular color
color = better_color(color, parse_one_color(comp))
- return {"color": color, "background": background_color, "bold": bold, "underline": underline}
+ return {"color": color, "background": background_color, "bold": bold,
+ "underline": underline}
+
def parse_bool(val):
val = val.lower()
- if val.startswith('f') or val.startswith('0'): return False
- if val.startswith('t') or val.startswith('1'): return True
+ if val.startswith('f') or val.startswith('0'):
+ return False
+ if val.startswith('t') or val.startswith('1'):
+ return True
return bool(val)
+
def html_color_for_ansi_color_index(val):
- arr = ['black', '#AA0000', '#00AA00', '#AA5500', '#0000AA', '#AA00AA', '#00AAAA', '#AAAAAA', '#555555', '#FF5555', '#55FF55', '#FFFF55', '#5555FF', '#FF55FF', '#55FFFF', 'white', '#000000', '#00005f', '#000087', '#0000af', '#0000d7', '#0000ff', '#005f00', '#005f5f', '#005f87', '#005faf', '#005fd7', '#005fff', '#008700', '#00875f', '#008787', '#0087af', '#0087d7', '#0087ff', '#00af00', '#00af5f', '#00af87', '#00afaf', '#00afd7', '#00afff', '#00d700', '#00d75f', '#00d787', '#00d7af', '#00d7d7', '#00d7ff', '#00ff00', '#00ff5f', '#00ff87', '#00ffaf', '#00ffd7', '#00ffff', '#5f0000', '#5f005f', '#5f0087', '#5f00af', '#5f00d7', '#5f00ff', '#5f5f00', '#5f5f5f', '#5f5f87', '#5f5faf', '#5f5fd7', '#5f5fff', '#5f8700', '#5f875f', '#5f8787', '#5f87af', '#5f87d7', '#5f87ff', '#5faf00', '#5faf5f', '#5faf87', '#5fafaf', '#5fafd7', '#5fafff', '#5fd700', '#5fd75f', '#5fd787', '#5fd7af', '#5fd7d7', '#5fd7ff', '#5fff00', '#5fff5f', '#5fff87', '#5fffaf', '#5fffd7', '#5fffff', '#870000', '#87005f', '#870087', '#8700af', '#8700d7', '#8700ff', '#875f00', '#875f5f', '#875f87', '#875faf', '#875fd7', '#875fff', '#878700', '#87875f', '#878787', '#8787af', '#8787d7', '#8787ff', '#87af00', '#87af5f', '#87af87', '#87afaf', '#87afd7', '#87afff', '#87d700', '#87d75f', '#87d787', '#87d7af', '#87d7d7', '#87d7ff', '#87ff00', '#87ff5f', '#87ff87', '#87ffaf', '#87ffd7', '#87ffff', '#af0000', '#af005f', '#af0087', '#af00af', '#af00d7', '#af00ff', '#af5f00', '#af5f5f', '#af5f87', '#af5faf', '#af5fd7', '#af5fff', '#af8700', '#af875f', '#af8787', '#af87af', '#af87d7', '#af87ff', '#afaf00', '#afaf5f', '#afaf87', '#afafaf', '#afafd7', '#afafff', '#afd700', '#afd75f', '#afd787', '#afd7af', '#afd7d7', '#afd7ff', '#afff00', '#afff5f', '#afff87', '#afffaf', '#afffd7', '#afffff', '#d70000', '#d7005f', '#d70087', '#d700af', '#d700d7', '#d700ff', '#d75f00', '#d75f5f', '#d75f87', '#d75faf', '#d75fd7', '#d75fff', '#d78700', '#d7875f', '#d78787', '#d787af', '#d787d7', '#d787ff', '#d7af00', '#d7af5f', '#d7af87', '#d7afaf', '#d7afd7', '#d7afff', '#d7d700', '#d7d75f', '#d7d787', '#d7d7af', '#d7d7d7', '#d7d7ff', '#d7ff00', '#d7ff5f', '#d7ff87', '#d7ffaf', '#d7ffd7', '#d7ffff', '#ff0000', '#ff005f', '#ff0087', '#ff00af', '#ff00d7', '#ff00ff', '#ff5f00', '#ff5f5f', '#ff5f87', '#ff5faf', '#ff5fd7', '#ff5fff', '#ff8700', '#ff875f', '#ff8787', '#ff87af', '#ff87d7', '#ff87ff', '#ffaf00', '#ffaf5f', '#ffaf87', '#ffafaf', '#ffafd7', '#ffafff', '#ffd700', '#ffd75f', '#ffd787', '#ffd7af', '#ffd7d7', '#ffd7ff', '#ffff00', '#ffff5f', '#ffff87', '#ffffaf', '#ffffd7', '#ffffff', '#080808', '#121212', '#1c1c1c', '#262626', '#303030', '#3a3a3a', '#444444', '#4e4e4e', '#585858', '#626262', '#6c6c6c', '#767676', '#808080', '#8a8a8a', '#949494', '#9e9e9e', '#a8a8a8', '#b2b2b2', '#bcbcbc', '#c6c6c6', '#d0d0d0', '#dadada', '#e4e4e4', '#eeeeee']
+ arr = ['black', '#AA0000', '#00AA00', '#AA5500', '#0000AA', '#AA00AA',
+ '#00AAAA', '#AAAAAA', '#555555', '#FF5555', '#55FF55', '#FFFF55',
+ '#5555FF', '#FF55FF', '#55FFFF', 'white', '#000000', '#00005f',
+ '#000087', '#0000af', '#0000d7', '#0000ff', '#005f00', '#005f5f',
+ '#005f87', '#005faf', '#005fd7', '#005fff', '#008700', '#00875f',
+ '#008787', '#0087af', '#0087d7', '#0087ff', '#00af00', '#00af5f',
+ '#00af87', '#00afaf', '#00afd7', '#00afff', '#00d700', '#00d75f',
+ '#00d787', '#00d7af', '#00d7d7', '#00d7ff', '#00ff00', '#00ff5f',
+ '#00ff87', '#00ffaf', '#00ffd7', '#00ffff', '#5f0000', '#5f005f',
+ '#5f0087', '#5f00af', '#5f00d7', '#5f00ff', '#5f5f00', '#5f5f5f',
+ '#5f5f87', '#5f5faf', '#5f5fd7', '#5f5fff', '#5f8700', '#5f875f',
+ '#5f8787', '#5f87af', '#5f87d7', '#5f87ff', '#5faf00', '#5faf5f',
+ '#5faf87', '#5fafaf', '#5fafd7', '#5fafff', '#5fd700', '#5fd75f',
+ '#5fd787', '#5fd7af', '#5fd7d7', '#5fd7ff', '#5fff00', '#5fff5f',
+ '#5fff87', '#5fffaf', '#5fffd7', '#5fffff', '#870000', '#87005f',
+ '#870087', '#8700af', '#8700d7', '#8700ff', '#875f00', '#875f5f',
+ '#875f87', '#875faf', '#875fd7', '#875fff', '#878700', '#87875f',
+ '#878787', '#8787af', '#8787d7', '#8787ff', '#87af00', '#87af5f',
+ '#87af87', '#87afaf', '#87afd7', '#87afff', '#87d700', '#87d75f',
+ '#87d787', '#87d7af', '#87d7d7', '#87d7ff', '#87ff00', '#87ff5f',
+ '#87ff87', '#87ffaf', '#87ffd7', '#87ffff', '#af0000', '#af005f',
+ '#af0087', '#af00af', '#af00d7', '#af00ff', '#af5f00', '#af5f5f',
+ '#af5f87', '#af5faf', '#af5fd7', '#af5fff', '#af8700', '#af875f',
+ '#af8787', '#af87af', '#af87d7', '#af87ff', '#afaf00', '#afaf5f',
+ '#afaf87', '#afafaf', '#afafd7', '#afafff', '#afd700', '#afd75f',
+ '#afd787', '#afd7af', '#afd7d7', '#afd7ff', '#afff00', '#afff5f',
+ '#afff87', '#afffaf', '#afffd7', '#afffff', '#d70000', '#d7005f',
+ '#d70087', '#d700af', '#d700d7', '#d700ff', '#d75f00', '#d75f5f',
+ '#d75f87', '#d75faf', '#d75fd7', '#d75fff', '#d78700', '#d7875f',
+ '#d78787', '#d787af', '#d787d7', '#d787ff', '#d7af00', '#d7af5f',
+ '#d7af87', '#d7afaf', '#d7afd7', '#d7afff', '#d7d700', '#d7d75f',
+ '#d7d787', '#d7d7af', '#d7d7d7', '#d7d7ff', '#d7ff00', '#d7ff5f',
+ '#d7ff87', '#d7ffaf', '#d7ffd7', '#d7ffff', '#ff0000', '#ff005f',
+ '#ff0087', '#ff00af', '#ff00d7', '#ff00ff', '#ff5f00', '#ff5f5f',
+ '#ff5f87', '#ff5faf', '#ff5fd7', '#ff5fff', '#ff8700', '#ff875f',
+ '#ff8787', '#ff87af', '#ff87d7', '#ff87ff', '#ffaf00', '#ffaf5f',
+ '#ffaf87', '#ffafaf', '#ffafd7', '#ffafff', '#ffd700', '#ffd75f',
+ '#ffd787', '#ffd7af', '#ffd7d7', '#ffd7ff', '#ffff00', '#ffff5f',
+ '#ffff87', '#ffffaf', '#ffffd7', '#ffffff', '#080808', '#121212',
+ '#1c1c1c', '#262626', '#303030', '#3a3a3a', '#444444', '#4e4e4e',
+ '#585858', '#626262', '#6c6c6c', '#767676', '#808080', '#8a8a8a',
+ '#949494', '#9e9e9e', '#a8a8a8', '#b2b2b2', '#bcbcbc', '#c6c6c6',
+ '#d0d0d0', '#dadada', '#e4e4e4', '#eeeeee']
if val < 0 or val >= len(arr):
return ''
else:
@@ -149,6 +195,8 @@ def html_color_for_ansi_color_index(val):
# Function to return special ANSI escapes like exit_attribute_mode
g_special_escapes_dict = None
+
+
def get_special_ansi_escapes():
global g_special_escapes_dict
if g_special_escapes_dict is None:
@@ -160,8 +208,10 @@ def get_special_ansi_escapes():
def get_tparm(key):
val = None
key = curses.tigetstr("sgr0")
- if key: val = curses.tparm(key)
- if val: val = val.decode('utf-8')
+ if key:
+ val = curses.tparm(key)
+ if val:
+ val = val.decode('utf-8')
return val
# Just a few for now
@@ -173,6 +223,8 @@ def get_special_ansi_escapes():
# Given a known ANSI escape sequence, convert it to HTML and append to the list
# Returns whether we have an open
+
+
def append_html_for_ansi_escape(full_val, result, span_open):
# Strip off the initial \x1b[ and terminating m
@@ -187,16 +239,16 @@ def append_html_for_ansi_escape(full_val, result, span_open):
match = re.match('38;5;(\d+)', val)
if match is not None:
close_span()
- html_color = html_color_for_ansi_color_index(int(match.group(1)))
+ html_color = html_color_for_ansi_color_index(int(match.group(1)))
result.append('')
- return True # span now open
+ return True # span now open
# term8 foreground color
if val in [str(x) for x in range(30, 38)]:
close_span()
- html_color = html_color_for_ansi_color_index(int(val) - 30)
+ html_color = html_color_for_ansi_color_index(int(val) - 30)
result.append('')
- return True # span now open
+ return True # span now open
# Try special escapes
special_escapes = get_special_ansi_escapes()
@@ -209,15 +261,17 @@ def append_html_for_ansi_escape(full_val, result, span_open):
# Do nothing on failure
return span_open
+
def strip_ansi(val):
# Make a half-assed effort to strip ANSI control sequences
# We assume that all such sequences start with 0x1b and end with m,
# which catches most cases
return re.sub("\x1b[^m]*m", '', val)
+
def ansi_prompt_line_width(val):
- # Given an ANSI prompt, return the length of its longest line, as in the number of characters it takes up
- # Start by stripping off ANSI
+ # Given an ANSI prompt, return the length of its longest line, as in the
+ # number of characters it takes up. Start by stripping off ANSI.
stripped_val = strip_ansi(val)
# Now count the longest line
@@ -225,10 +279,10 @@ def ansi_prompt_line_width(val):
def ansi_to_html(val):
- # Split us up by ANSI escape sequences
- # We want to catch not only the standard color codes, but also things like sgr0
- # Hence this lame check
- # Note that Python 2.6 doesn't have a flag param to re.split, so we have to compile it first
+ # Split us up by ANSI escape sequences. We want to catch not only the
+ # standard color codes, but also things like sgr0. Hence this lame check.
+ # Note that Python 2.6 doesn't have a flag param to re.split, so we have to
+ # compile it first.
reg = re.compile("""
( # Capture
\x1b # Escape
@@ -253,10 +307,12 @@ def ansi_to_html(val):
result.append(cgi.escape(strip_ansi(component)))
else:
# It's an escape sequence. Close the previous escape.
- span_open = append_html_for_ansi_escape(component, result, span_open)
+ span_open = append_html_for_ansi_escape(component, result,
+ span_open)
# Close final escape
- if span_open: result.append('')
+ if span_open:
+ result.append('')
# Remove empty elements
result = [x for x in result if x]
@@ -272,6 +328,7 @@ def ansi_to_html(val):
return ''.join(result)
+
class FishVar:
""" A class that represents a variable """
def __init__(self, name, value):
@@ -283,15 +340,20 @@ class FishVar:
def get_json_obj(self):
# Return an array(3): name, value, flags
flags = []
- if self.universal: flags.append('universal')
- if self.exported: flags.append('exported')
- return {"name": self.name, "value": self.value, "Flags": ', '.join(flags)}
+ if self.universal:
+ flags.append('universal')
+ if self.exported:
+ flags.append('exported')
+ return {"name": self.name, "value": self.value,
+ "Flags": ', '.join(flags)}
+
class FishBinding:
"""A class that represents keyboard binding """
- def __init__(self, command, raw_binding, readable_binding, description=None):
- self.command = command
+ def __init__(self, command, raw_binding, readable_binding,
+ description=None):
+ self.command = command
self.bindings = []
self.description = description
self.add_binding(raw_binding, readable_binding)
@@ -302,23 +364,24 @@ class FishBinding:
i['raw_bindings'].append(raw_binding)
break
else:
- self.bindings.append({'readable_binding':readable_binding, 'raw_bindings':[raw_binding]})
+ self.bindings.append({'readable_binding': readable_binding,
+ 'raw_bindings': [raw_binding]})
def get_json_obj(self):
- return {"command" : self.command, "bindings": self.bindings, "description": self.description}
+ return {"command": self.command, "bindings": self.bindings,
+ "description": self.description}
class BindingParser:
""" Class to parse codes for bind command """
- #TODO: What does snext and sprevious mean ?
- readable_keys= { "dc":"Delete", "npage": "Page Up", "ppage":"Page Down",
- "sdc": "Shift Delete", "shome": "Shift Home",
- "left": "Left Arrow", "right": "Right Arrow",
- "up": "Up Arrow", "down": "Down Arrow",
- "sleft": "Shift Left", "sright": "Shift Right",
- "btab": "Shift Tab"
- }
+ # TODO: What does snext and sprevious mean ?
+ readable_keys = {"dc": "Delete", "npage": "Page Up", "ppage": "Page Down",
+ "sdc": "Shift Delete", "shome": "Shift Home",
+ "left": "Left Arrow", "right": "Right Arrow",
+ "up": "Up Arrow", "down": "Down Arrow",
+ "sleft": "Shift Left", "sright": "Shift Right",
+ "btab": "Shift Tab"}
def set_buffer(self, buffer):
""" Sets code to parse """
@@ -356,7 +419,8 @@ class BindingParser:
# \[1\; is start of control sequence
if c == '1':
- b = self.get_char(); c = self.get_char()
+ b = self.get_char()
+ c = self.get_char()
if b == '\\' and c == '~':
result += "Home"
elif c == ";":
@@ -369,7 +433,8 @@ class BindingParser:
# \[4\~ is End
if c == '4':
- b = self.get_char(); c = self.get_char()
+ b = self.get_char()
+ c = self.get_char()
if b == '\\' and c == '~':
result += "End"
@@ -466,7 +531,7 @@ class FishConfigTCPServer(SocketServer.TCPServer):
"""TCPServer that only accepts connections from localhost (IPv4/IPv6)."""
WHITELIST = set(['::1', '::ffff:127.0.0.1', '127.0.0.1'])
- address_family = socket.AF_INET6 if HAS_IPV6 else socket.AF_INET
+ address_family = socket.AF_INET6 if socket.has_ipv6 else socket.AF_INET
def verify_request(self, request, client_address):
return client_address[0] in FishConfigTCPServer.WHITELIST
@@ -526,7 +591,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
for match in re.finditer(r"^fish_color_(\S+) ?(.*)", line):
color_name, color_value = [x.strip() for x in match.group(1, 2)]
color_desc = descriptions.get(color_name, '')
- data = { "name": color_name, "description" : color_desc }
+ data = {"name": color_name, "description": color_desc}
data.update(parse_color(color_value))
result.append(data)
remaining.discard(color_name)
@@ -564,18 +629,22 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
vars = {}
for line in out.split('\n'):
comps = line.split(' ', 1)
- if len(comps) < 2: continue
+ if len(comps) < 2:
+ continue
fish_var = FishVar(comps[0], comps[1])
vars[fish_var.name] = fish_var
# Mark universal variables. L means don't abbreviate.
for name in self.do_get_variable_names('set -nUL'):
- if name in vars: vars[name].universal = True
+ if name in vars:
+ vars[name].universal = True
# Mark exported variables. L means don't abbreviate.
for name in self.do_get_variable_names('set -nxL'):
- if name in vars: vars[name].exported = True
+ if name in vars:
+ vars[name].exported = True
- return [vars[key].get_json_obj() for key in sorted(vars.keys(), key=lambda x: x.lower())]
+ return [vars[key].get_json_obj() for key
+ in sorted(vars.keys(), key=lambda x: x.lower())]
def do_get_bindings(self):
""" Get key bindings """
@@ -621,29 +690,37 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
bindings.append(fish_binding)
command_to_binding[command] = fish_binding
- return [ binding.get_json_obj() for binding in bindings ]
+ return [binding.get_json_obj() for binding in bindings]
def do_get_history(self):
- # Use \x1e ("record separator") to distinguish between history items. The first
- # backslash is so Python passes one backslash to fish
+ # Use \x1e ("record separator") to distinguish between history items.
+ # The first backslash is so Python passes one backslash to fish.
out, err = run_fish_cmd('for val in $history; echo -n $val \\x1e; end')
result = out.split(' \x1e')
- if result: result.pop() # Trim off the trailing element
+ if result:
+ result.pop() # trim off the trailing element
return result
def do_get_color_for_variable(self, name):
- "Return the color with the given name, or the empty string if there is none"
+ # Return the color with the given name, or the empty string if there is
+ # none.
out, err = run_fish_cmd("echo -n $" + name)
return out
- def do_set_color_for_variable(self, name, color, background_color, bold, underline):
- if not color: color = 'normal'
+ def do_set_color_for_variable(self, name, color, background_color, bold,
+ underline):
+ if not color:
+ color = 'normal'
"Sets a color for a fish color name, like 'autosuggestion'"
command = 'set -U fish_color_' + name
- if color: command += ' ' + color
- if background_color: command += ' --background=' + background_color
- if bold: command += ' --bold'
- if underline: command += ' --underline'
+ if color:
+ command += ' ' + color
+ if background_color:
+ command += ' --background=' + background_color
+ if bold:
+ command += ' --bold'
+ if underline:
+ command += ' --underline'
out, err = run_fish_cmd(command)
return out
@@ -655,7 +732,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_delete_history_item(self, history_item_text):
# It's really lame that we always return success here
cmd = ('builtin history delete --exact -- %s; builtin history save' %
- escape_fish_cmd(history_item_text))
+ escape_fish_cmd(history_item_text))
out, err = run_fish_cmd(cmd)
return True
@@ -669,29 +746,35 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
prompt_demo_ansi, err = run_fish_cmd(command_to_run)
prompt_demo_html = ansi_to_html(prompt_demo_ansi)
prompt_demo_font_size = self.font_size_for_ansi_prompt(prompt_demo_ansi)
- result = {'function': prompt_function_text, 'demo': prompt_demo_html, 'font_size': prompt_demo_font_size }
+ result = {'function': prompt_function_text, 'demo': prompt_demo_html,
+ 'font_size': prompt_demo_font_size}
if extras_dict:
result.update(extras_dict)
return result
def do_get_current_prompt(self):
- # Return the current prompt
- # We run 'false' to demonstrate how the prompt shows the command status (#1624)
+ # Return the current prompt. We run 'false' to demonstrate how the
+ # prompt shows the command status (#1624).
prompt_func, err = run_fish_cmd('functions fish_prompt')
- result = self.do_get_prompt('builtin cd "' + initial_wd + '" ; false ; fish_prompt', prompt_func.strip(), {'name': 'Current'})
+ result = self.do_get_prompt(
+ 'builtin cd "' + initial_wd + '" ; false ; fish_prompt',
+ prompt_func.strip(), {'name': 'Current'})
return result
def do_get_sample_prompt(self, text, extras_dict):
- # Return the prompt you get from the given text
- # extras_dict is a dictionary whose values get merged in
- # We run 'false' to demonstrate how the prompt shows the command status (#1624)
- cmd = text + "\n builtin cd \"" + initial_wd + "\" \n false \n fish_prompt\n"
+ # Return the prompt you get from the given text. Extras_dict is a
+ # dictionary whose values get merged in. We run 'false' to demonstrate
+ # how the prompt shows the command status (#1624)
+ cmd = (text + "\n builtin cd \"" + initial_wd +
+ "\" \n false \n fish_prompt\n")
return self.do_get_prompt(cmd, text.strip(), extras_dict)
def parse_one_sample_prompt_hash(self, line, result_dict):
# Allow us to skip whitespace, etc.
- if not line: return True
- if line.isspace(): return True
+ if not line:
+ return True
+ if line.isspace():
+ return True
# Parse a comment hash like '# name: Classic'
match = re.match(r"#\s*(\w+?): (.+)", line, re.IGNORECASE)
@@ -703,7 +786,6 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
# Skip other hash comments
return line.startswith('#')
-
def read_one_sample_prompt(self, path):
try:
with open(path, 'rb') as fd:
@@ -713,10 +795,13 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
parsing_hashes = True
unicode_lines = (line.decode('utf-8') for line in fd)
for line in unicode_lines:
- # Parse hashes until parse_one_sample_prompt_hash return False
+ # Parse hashes until parse_one_sample_prompt_hash return
+ # False.
if parsing_hashes:
- parsing_hashes = self.parse_one_sample_prompt_hash(line, extras_dict)
- # Maybe not we're not parsing hashes, or maybe we already were not
+ parsing_hashes = self.parse_one_sample_prompt_hash(
+ line, extras_dict)
+ # Maybe not we're not parsing hashes, or maybe we already
+ # were not.
if not parsing_hashes:
function_lines.append(line)
func = ''.join(function_lines).strip()
@@ -752,37 +837,46 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_remove_abbreviation(self, abbreviation):
out, err = run_fish_cmd('abbr --erase %s' % abbreviation['word'])
- if out or err:
- return err
- else:
- return True
-
- def do_save_abbreviation(self, abbreviation):
- out, err = run_fish_cmd('abbr --add \'%s %s\'' % (abbreviation['word'], abbreviation['phrase']))
if err:
return err
else:
- return True
+ return None
+
+ def do_save_abbreviation(self, abbreviation):
+ out, err = run_fish_cmd('abbr --add \'%s\' \'%s\'' % (
+ abbreviation['word'], abbreviation['phrase']))
+ if err:
+ return err
+ else:
+ return None
def secure_startswith(self, haystack, needle):
if len(haystack) < len(needle):
return False
bits = 0
- for x,y in zip(haystack, needle):
+ for x, y in zip(haystack, needle):
bits |= ord(x) ^ ord(y)
return bits == 0
def font_size_for_ansi_prompt(self, prompt_demo_ansi):
width = ansi_prompt_line_width(prompt_demo_ansi)
# Pick a font size
- if width >= 70: font_size = '8pt'
- if width >= 60: font_size = '10pt'
- elif width >= 50: font_size = '11pt'
- elif width >= 40: font_size = '13pt'
- elif width >= 30: font_size = '15pt'
- elif width >= 25: font_size = '16pt'
- elif width >= 20: font_size = '17pt'
- else: font_size = '18pt'
+ if width >= 70:
+ font_size = '8pt'
+ if width >= 60:
+ font_size = '10pt'
+ elif width >= 50:
+ font_size = '11pt'
+ elif width >= 40:
+ font_size = '13pt'
+ elif width >= 30:
+ font_size = '15pt'
+ elif width >= 25:
+ font_size = '16pt'
+ elif width >= 20:
+ font_size = '17pt'
+ else:
+ font_size = '18pt'
return font_size
def do_GET(self):
@@ -820,7 +914,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
# Return valid output
self.send_response(200)
- self.send_header('Content-type','application/json')
+ self.send_header('Content-type', 'application/json')
self.end_headers()
self.write_to_wfile('\n')
@@ -861,7 +955,9 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
if what:
# Not sure why we get lists here?
- output = self.do_set_color_for_variable(what[0], color[0], background_color[0], parse_bool(bold[0]), parse_bool(underline[0]))
+ output = self.do_set_color_for_variable(
+ what[0], color[0], background_color[0],
+ parse_bool(bold[0]), parse_bool(underline[0]))
else:
output = 'Bad request'
elif p == '/get_function/':
@@ -880,23 +976,23 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
else:
output = ["Unable to set prompt"]
elif p == '/save_abbreviation/':
- r = self.do_save_abbreviation(postvars)
- if r == True:
- output = ["OK"]
+ errmsg = self.do_save_abbreviation(postvars)
+ if errmsg:
+ output = [errmsg]
else:
- output = [r]
+ output = ["OK"]
elif p == '/remove_abbreviation/':
- r = self.do_remove_abbreviation(postvars)
- if r == True:
- output = ["OK"]
+ errmsg = self.do_remove_abbreviation(postvars)
+ if errmsg:
+ output = [errmsg]
else:
- output = [r]
+ output = ["OK"]
else:
return self.send_error(404)
# Return valid output
self.send_response(200)
- self.send_header('Content-type','application/json')
+ self.send_header('Content-type', 'application/json')
self.end_headers()
self.write_to_wfile('\n')
@@ -932,7 +1028,8 @@ redirect_template_html = """
fish_bin_dir = os.environ.get('__fish_bin_dir')
fish_bin_path = None
if not fish_bin_dir:
- print('The __fish_bin_dir environment variable is not set. Looking in $PATH...')
+ print('The __fish_bin_dir environment variable is not set. '
+ 'Looking in $PATH...')
# distutils.spawn is terribly broken, because it looks in wd before PATH,
# and doesn't actually validate that the file is even executable
for p in os.environ['PATH'].split(os.pathsep):
@@ -950,7 +1047,8 @@ else:
fish_bin_path = os.path.join(fish_bin_dir, 'fish')
if not os.access(fish_bin_path, os.X_OK):
- print("fish could not be executed at path '%s'. Is fish installed correctly?" % fish_bin_path)
+ print("fish could not be executed at path '%s'. "
+ "Is fish installed correctly?" % fish_bin_path)
sys.exit(-1)
FISH_BIN_PATH = fish_bin_path
@@ -958,8 +1056,8 @@ FISH_BIN_PATH = fish_bin_path
# so get the current working directory
initial_wd = os.getcwd()
-# Make sure that the working directory is the one that contains the script server file,
-# because the document root is the working directory
+# Make sure that the working directory is the one that contains the script
+# server file, because the document root is the working directory.
where = os.path.dirname(sys.argv[0])
os.chdir(where)
@@ -968,7 +1066,7 @@ authkey = binascii.b2a_hex(os.urandom(16)).decode('ascii')
# Try to find a suitable port
PORT = 8000
-HOST = "::" if HAS_IPV6 else "localhost"
+HOST = "::" if socket.has_ipv6 else "localhost"
while PORT <= 9000:
try:
Handler = FishConfigHTTPRequestHandler
@@ -992,16 +1090,17 @@ if PORT > 9000:
# Just look at the first letter
initial_tab = ''
if len(sys.argv) > 1:
- for tab in ['functions', 'prompt', 'colors', 'variables', 'history', 'bindings', 'abbreviations']:
+ for tab in ['functions', 'prompt', 'colors', 'variables', 'history',
+ 'bindings', 'abbreviations']:
if tab.startswith(sys.argv[1]):
initial_tab = '#' + tab
break
url = 'http://localhost:%d/%s/%s' % (PORT, authkey, initial_tab)
-# Create temporary file to hold redirect to real server
-# This prevents exposing the URL containing the authentication key on the command line
-# (see CVE-2014-2914 or https://github.com/fish-shell/fish-shell/issues/1438)
+# Create temporary file to hold redirect to real server. This prevents exposing
+# the URL containing the authentication key on the command line (see
+# CVE-2014-2914 or https://github.com/fish-shell/fish-shell/issues/1438).
if 'XDG_CACHE_HOME' in os.environ:
dirname = os.path.expanduser(os.path.expandvars('$XDG_CACHE_HOME/fish/'))
else:
@@ -1012,11 +1111,12 @@ try:
os.makedirs(dirname, 0o0700)
except OSError as e:
if e.errno == 17:
- pass
+ pass
else:
- raise e
+ raise e
-randtoken = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6))
+randtoken = ''.join(random.choice(string.ascii_uppercase + string.digits)
+ for _ in range(6))
filename = dirname + 'web_config-%s.html' % randtoken
f = open(filename, 'w')
diff --git a/src/autoload.cpp b/src/autoload.cpp
index a10de1364..0b25b6f4d 100644
--- a/src/autoload.cpp
+++ b/src/autoload.cpp
@@ -1,7 +1,6 @@
// The classes responsible for autoloading functions and completions.
#include "config.h" // IWYU pragma: keep
-#include
#include
#include
#include
@@ -26,7 +25,7 @@
static const int kAutoloadStalenessInterval = 15;
file_access_attempt_t access_file(const wcstring &path, int mode) {
- // printf("Touch %ls\n", path.c_str());
+ // fwprintf(stderr, L"Touch %ls\n", path.c_str());
file_access_attempt_t result = {};
struct stat statbuf;
if (wstat(path, &statbuf)) {
@@ -47,24 +46,22 @@ file_access_attempt_t access_file(const wcstring &path, int mode) {
return result;
}
-autoload_t::autoload_t(const wcstring &env_var_name_var, const builtin_script_t *const scripts,
- size_t script_count)
+autoload_t::autoload_t(const wcstring &env_var_name_var,
+ command_removed_function_t cmd_removed_callback)
: lock(),
env_var_name(env_var_name_var),
- builtin_scripts(scripts),
- builtin_script_count(script_count) {
+ command_removed(cmd_removed_callback) {
pthread_mutex_init(&lock, NULL);
}
autoload_t::~autoload_t() { pthread_mutex_destroy(&lock); }
-void autoload_t::node_was_evicted(autoload_function_t *node) {
+void autoload_t::entry_was_evicted(wcstring key, autoload_function_t node) {
// This should only ever happen on the main thread.
ASSERT_IS_MAIN_THREAD();
// Tell ourselves that the command was removed if it was loaded.
- if (node->is_loaded) this->command_removed(node->key);
- delete node;
+ if (node.is_loaded) this->command_removed(std::move(key));
}
int autoload_t::unload(const wcstring &cmd) { return this->evict_node(cmd); }
@@ -123,15 +120,10 @@ bool autoload_t::can_load(const wcstring &cmd, const env_vars_snapshot_t &vars)
return this->locate_file_and_maybe_load_it(cmd, false, false, path_list);
}
-static bool script_name_precedes_script_name(const builtin_script_t &script1,
- const builtin_script_t &script2) {
- return wcscmp(script1.name, script2.name) < 0;
-}
-
/// Check whether the given command is loaded.
bool autoload_t::has_tried_loading(const wcstring &cmd) {
scoped_lock locker(lock);
- autoload_function_t *func = this->get_node(cmd);
+ autoload_function_t *func = this->get(cmd);
return func != NULL;
}
@@ -145,14 +137,16 @@ static bool is_stale(const autoload_function_t *func) {
autoload_function_t *autoload_t::get_autoloaded_function_with_creation(const wcstring &cmd,
bool allow_eviction) {
ASSERT_IS_LOCKED(lock);
- autoload_function_t *func = this->get_node(cmd);
+ autoload_function_t *func = this->get(cmd);
if (!func) {
- func = new autoload_function_t(cmd);
+ bool added;
if (allow_eviction) {
- this->add_node(func);
+ added = this->insert(cmd, autoload_function_t(false));
} else {
- this->add_node_without_eviction(func);
+ added = this->insert_no_eviction(cmd, autoload_function_t(false));
}
+ func = this->get(cmd);
+ assert(func);
}
return func;
}
@@ -189,7 +183,7 @@ bool autoload_t::locate_file_and_maybe_load_it(const wcstring &cmd, bool really_
{
bool allow_stale_functions = !reload;
scoped_lock locker(lock);
- autoload_function_t *func = this->get_node(cmd); // get the function
+ autoload_function_t *func = this->get(cmd); // get the function
// If we can use this function, return whether we were able to access it.
if (use_cached(func, really_load, allow_stale_functions)) {
@@ -199,110 +193,78 @@ bool autoload_t::locate_file_and_maybe_load_it(const wcstring &cmd, bool really_
// The source of the script will end up here.
wcstring script_source;
- bool has_script_source = false;
// Whether we found an accessible file.
bool found_file = false;
- // Look for built-in scripts via a binary search.
- const builtin_script_t *matching_builtin_script = NULL;
- if (builtin_script_count > 0) {
- const builtin_script_t test_script = {cmd.c_str(), NULL};
- const builtin_script_t *array_end = builtin_scripts + builtin_script_count;
- const builtin_script_t *found = std::lower_bound(builtin_scripts, array_end, test_script,
- script_name_precedes_script_name);
- if (found != array_end && !wcscmp(found->name, test_script.name)) {
- matching_builtin_script = found;
- }
- }
- if (matching_builtin_script) {
- has_script_source = true;
- script_source = str2wcstring(matching_builtin_script->def);
+ // Iterate over path searching for suitable completion files.
+ for (size_t i = 0; i < path_list.size() && !found_file; i++) {
+ wcstring next = path_list.at(i);
+ wcstring path = next + L"/" + cmd + L".fish";
- // Make a node representing this function.
+ const file_access_attempt_t access = access_file(path, R_OK);
+ if (!access.accessible) {
+ continue;
+ }
+
+ // Now we're actually going to take the lock.
scoped_lock locker(lock);
- autoload_function_t *func = this->get_autoloaded_function_with_creation(cmd, really_load);
+ autoload_function_t *func = this->get(cmd);
- // This function is internalized.
- func->is_internalized = true;
+ // Generate the source if we need to load it.
+ bool need_to_load_function =
+ really_load &&
+ (func == NULL || func->access.mod_time != access.mod_time || !func->is_loaded);
+ if (need_to_load_function) {
+ // Generate the script source.
+ script_source = L"source " + escape_string(path, ESCAPE_ALL);
- // It's a fiction to say the script is loaded at this point, but we're definitely going to
- // load it down below.
- if (really_load) func->is_loaded = true;
+ // Remove any loaded command because we are going to reload it. Note that this
+ // will deadlock if command_removed calls back into us.
+ if (func && func->is_loaded) {
+ command_removed(cmd);
+ func->is_placeholder = false;
+ }
+
+ // Mark that we're reloading it.
+ reloaded = true;
+ }
+
+ // Create the function if we haven't yet. This does not load it. Do not trigger
+ // eviction unless we are actually loading, because we don't want to evict off of
+ // the main thread.
+ if (!func) func = get_autoloaded_function_with_creation(cmd, really_load);
+
+ // It's a fiction to say the script is loaded at this point, but we're definitely
+ // going to load it down below.
+ if (need_to_load_function) func->is_loaded = true;
+
+ // Unconditionally record our access time.
+ func->access = access;
+ found_file = true;
}
- if (!has_script_source) {
- // Iterate over path searching for suitable completion files.
- for (size_t i = 0; i < path_list.size() && !found_file; i++) {
- wcstring next = path_list.at(i);
- wcstring path = next + L"/" + cmd + L".fish";
-
- const file_access_attempt_t access = access_file(path, R_OK);
- if (!access.accessible) {
- continue;
+ // If no file or builtin script was found we insert a placeholder function. Later we only
+ // research if the current time is at least five seconds later. This way, the files won't be
+ // searched over and over again.
+ if (!found_file && script_source.empty()) {
+ scoped_lock locker(lock);
+ // Generate a placeholder.
+ autoload_function_t *func = this->get(cmd);
+ if (!func) {
+ if (really_load) {
+ this->insert(cmd, autoload_function_t(true));
+ } else {
+ this->insert(cmd, autoload_function_t(true));
}
-
- // Now we're actually going to take the lock.
- scoped_lock locker(lock);
- autoload_function_t *func = this->get_node(cmd);
-
- // Generate the source if we need to load it.
- bool need_to_load_function =
- really_load &&
- (func == NULL || func->access.mod_time != access.mod_time || !func->is_loaded);
- if (need_to_load_function) {
- // Generate the script source.
- wcstring esc = escape_string(path, 1);
- script_source = L"source " + esc;
- has_script_source = true;
-
- // Remove any loaded command because we are going to reload it. Note that this
- // will deadlock if command_removed calls back into us.
- if (func && func->is_loaded) {
- command_removed(cmd);
- func->is_placeholder = false;
- }
-
- // Mark that we're reloading it.
- reloaded = true;
- }
-
- // Create the function if we haven't yet. This does not load it. Do not trigger
- // eviction unless we are actually loading, because we don't want to evict off of
- // the main thread.
- if (!func) func = get_autoloaded_function_with_creation(cmd, really_load);
-
- // It's a fiction to say the script is loaded at this point, but we're definitely
- // going to load it down below.
- if (need_to_load_function) func->is_loaded = true;
-
- // Unconditionally record our access time.
- func->access = access;
- found_file = true;
- }
-
- // If no file or builtin script was found we insert a placeholder function. Later we only
- // research if the current time is at least five seconds later. This way, the files won't be
- // searched over and over again.
- if (!found_file && !has_script_source) {
- scoped_lock locker(lock);
- // Generate a placeholder.
- autoload_function_t *func = this->get_node(cmd);
- if (!func) {
- func = new autoload_function_t(cmd);
- func->is_placeholder = true;
- if (really_load) {
- this->add_node(func);
- } else {
- this->add_node_without_eviction(func);
- }
- }
- func->access.last_checked = time(NULL);
+ func = this->get(cmd);
+ assert(func);
}
+ func->access.last_checked = time(NULL);
}
// If we have a script, either built-in or a file source, then run it.
- if (really_load && has_script_source) {
+ if (really_load && !script_source.empty()) {
// Do nothing on failure.
exec_subshell(script_source, false /* do not apply exit status */);
}
@@ -311,5 +273,5 @@ bool autoload_t::locate_file_and_maybe_load_it(const wcstring &cmd, bool really_
return reloaded;
}
- return found_file || has_script_source;
+ return found_file || !script_source.empty();
}
diff --git a/src/autoload.h b/src/autoload.h
index 49891828f..15ab14f27 100644
--- a/src/autoload.h
+++ b/src/autoload.h
@@ -25,13 +25,9 @@ struct file_access_attempt_t {
};
file_access_attempt_t access_file(const wcstring &path, int mode);
-struct autoload_function_t : public lru_node_t {
- explicit autoload_function_t(const wcstring &key)
- : lru_node_t(key),
- access(),
- is_loaded(false),
- is_placeholder(false),
- is_internalized(false) {}
+struct autoload_function_t {
+ explicit autoload_function_t(bool placeholder)
+ : access(), is_loaded(false), is_placeholder(placeholder), is_internalized(false) {}
/// The last access attempt recorded
file_access_attempt_t access;
@@ -44,24 +40,15 @@ struct autoload_function_t : public lru_node_t {
bool is_internalized;
};
-struct builtin_script_t {
- const wchar_t *name;
- const char *def;
-};
-
class env_vars_snapshot_t;
/// Class representing a path from which we can autoload and the autoloaded contents.
-class autoload_t : private lru_cache_t {
+class autoload_t : public lru_cache_t {
private:
/// Lock for thread safety.
pthread_mutex_t lock;
/// The environment variable name.
const wcstring env_var_name;
- /// Builtin script array.
- const struct builtin_script_t *const builtin_scripts;
- /// Builtin script count.
- const size_t builtin_script_count;
/// The path from which we most recently autoloaded.
wcstring last_path;
/// the most reecently autoloaded path, tokenized (split on separators).
@@ -69,27 +56,27 @@ class autoload_t : private lru_cache_t {
/// A table containing all the files that are currently being loaded.
/// This is here to help prevent recursion.
std::set is_loading_set;
+ // Function invoked when a command is removed
+ typedef void (*command_removed_function_t)(const wcstring &);
+ const command_removed_function_t command_removed;
- void remove_all_functions(void) { this->evict_all_nodes(); }
+ void remove_all_functions() { this->evict_all_nodes(); }
bool locate_file_and_maybe_load_it(const wcstring &cmd, bool really_load, bool reload,
const wcstring_list_t &path_list);
- virtual void node_was_evicted(autoload_function_t *node);
-
autoload_function_t *get_autoloaded_function_with_creation(const wcstring &cmd,
bool allow_eviction);
- protected:
- /// Overridable callback for when a command is removed.
- virtual void command_removed(const wcstring &cmd) { UNUSED(cmd); }
-
public:
- /// Create an autoload_t for the given environment variable name.
- autoload_t(const wcstring &env_var_name_var, const builtin_script_t *scripts,
- size_t script_count);
+ // CRTP override
+ void entry_was_evicted(wcstring key, autoload_function_t node);
- virtual ~autoload_t();
+ // Create an autoload_t for the given environment variable name.
+ autoload_t(const wcstring &env_var_name_var,
+ command_removed_function_t callback);
+
+ ~autoload_t();
/// Autoload the specified file, if it exists in the specified path. Do not load it multiple
/// times unless its timestamp changes or parse_util_unload is called.
diff --git a/src/builtin.cpp b/src/builtin.cpp
index 6172222a1..b66759e97 100644
--- a/src/builtin.cpp
+++ b/src/builtin.cpp
@@ -21,17 +21,18 @@
#include
#include
#include
+#include
#include
#include
#include
#include
-#include
+#include
#include
#include
-#include
#include
#include