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:
Dale Eidd 2018-06-24 12:18:22 +10:00 committed by Fabian Homborg
parent 49bfc4f000
commit 8e49229d8f

View file

@ -54,10 +54,9 @@ function __fish_print_hostnames -d "Print a list of known hostnames"
end
function _recursive --no-scope-shadowing
set -l orig_dir $PWD
set -l paths
for config in $argv
if test -r "$config"
if test -r "$config" -a -f "$config"
set paths $paths (
# Keep only Include lines and remove Include syntax
string replace -rfi '^\s*Include\s+' '' <$config \
@ -66,25 +65,24 @@ function __fish_print_hostnames -d "Print a list of known hostnames"
end
end
# Skip unusable paths.
test -d "$relative_path" -a -x "$relative_path"
or return
builtin cd $relative_path
set -l new_paths
for path in $paths
set -l expanded_path
eval "set expanded_path (printf \"%s\n\" $path)"
for path in $expanded_path
# Resolve "relative" paths in accordance to ssh path resolution
if string match -qv '/*' $path
# Scope "relative" paths in accordance to ssh path resolution
if string match -qrv '^[~/]' $path
set path $relative_path/$path
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
set new_paths $new_paths $path
end
end
builtin cd $orig_dir
if test -n "$new_paths"
_recursive $new_paths