mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
Fix & improve ssh_config Include directive for hostname printing
Fixes - Use the actual path when skipping unusable paths to fix all Include directives being skipped when there is no ~/.ssh directory - Prevent "No matches for wildcard" message Improvements - Skip paths that are directories since we only want files - Remove `cd` as it is not needed
This commit is contained in:
parent
49bfc4f000
commit
8e49229d8f
1 changed files with 11 additions and 13 deletions
|
@ -54,10 +54,9 @@ function __fish_print_hostnames -d "Print a list of known hostnames"
|
||||||
end
|
end
|
||||||
|
|
||||||
function _recursive --no-scope-shadowing
|
function _recursive --no-scope-shadowing
|
||||||
set -l orig_dir $PWD
|
|
||||||
set -l paths
|
set -l paths
|
||||||
for config in $argv
|
for config in $argv
|
||||||
if test -r "$config"
|
if test -r "$config" -a -f "$config"
|
||||||
set paths $paths (
|
set paths $paths (
|
||||||
# Keep only Include lines and remove Include syntax
|
# Keep only Include lines and remove Include syntax
|
||||||
string replace -rfi '^\s*Include\s+' '' <$config \
|
string replace -rfi '^\s*Include\s+' '' <$config \
|
||||||
|
@ -66,25 +65,24 @@ function __fish_print_hostnames -d "Print a list of known hostnames"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Skip unusable paths.
|
|
||||||
test -d "$relative_path" -a -x "$relative_path"
|
|
||||||
or return
|
|
||||||
|
|
||||||
builtin cd $relative_path
|
|
||||||
set -l new_paths
|
set -l new_paths
|
||||||
for path in $paths
|
for path in $paths
|
||||||
set -l expanded_path
|
set -l expanded_path
|
||||||
eval "set expanded_path (printf \"%s\n\" $path)"
|
# Scope "relative" paths in accordance to ssh path resolution
|
||||||
for path in $expanded_path
|
if string match -qrv '^[~/]' $path
|
||||||
# Resolve "relative" paths in accordance to ssh path resolution
|
|
||||||
if string match -qv '/*' $path
|
|
||||||
set path $relative_path/$path
|
set path $relative_path/$path
|
||||||
end
|
end
|
||||||
|
# Use `eval` to expand paths (eg ~/.ssh/../test/* to /home/<user>/test/file1 /home/<user>/test/file2),
|
||||||
|
# and `set` will prevent "No matches for wildcard" messages
|
||||||
|
eval set expanded_path $path
|
||||||
|
for path in $expanded_path
|
||||||
|
# Skip unusable paths.
|
||||||
|
test -r "$path" -a -f "$path"
|
||||||
|
or continue
|
||||||
echo $path
|
echo $path
|
||||||
set new_paths $new_paths $path
|
set new_paths $new_paths $path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
builtin cd $orig_dir
|
|
||||||
|
|
||||||
if test -n "$new_paths"
|
if test -n "$new_paths"
|
||||||
_recursive $new_paths
|
_recursive $new_paths
|
||||||
|
|
Loading…
Reference in a new issue