mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
__fish_print_hostnames: Use string replace -f
Saves one `string match` invocation. Also removes a useless-use-of-cat.
This commit is contained in:
parent
a4c03e3d7b
commit
4437e8d8d6
1 changed files with 9 additions and 9 deletions
|
@ -53,14 +53,14 @@ function __fish_print_hostnames -d "Print a list of known hostnames"
|
||||||
set -l orig_dir $PWD
|
set -l orig_dir $PWD
|
||||||
set -l paths
|
set -l paths
|
||||||
for config in $argv
|
for config in $argv
|
||||||
set paths $paths (cat $config ^/dev/null \
|
if test -r "$config"
|
||||||
# Keep only Include lines
|
set paths $paths (
|
||||||
| string match -r -i '^\s*Include\s+.+' \
|
# Keep only Include lines and remove Include syntax
|
||||||
# Remove Include syntax
|
string replace -rfi '^\s*Include\s+' '' <$config \
|
||||||
| string replace -r -i '^\s*Include\s+' '' \
|
|
||||||
# Normalize whitespace
|
# Normalize whitespace
|
||||||
| string trim | string replace -r -a '\s+' ' ')
|
| string trim | string replace -r -a '\s+' ' ')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
builtin cd $relative_path
|
builtin cd $relative_path
|
||||||
set -l new_paths
|
set -l new_paths
|
||||||
|
@ -89,9 +89,9 @@ function __fish_print_hostnames -d "Print a list of known hostnames"
|
||||||
for file in $ssh_configs
|
for file in $ssh_configs
|
||||||
if test -r $file
|
if test -r $file
|
||||||
# Print hosts from system wide ssh configuration file
|
# Print hosts from system wide ssh configuration file
|
||||||
string match -r -i '^\s*Host\s+\S+' <$file | string replace -r -i '^\s*Host\s+' '' | string trim | string replace -r '\s+' ' ' | string split ' ' | string match -v '*\**'
|
string replace -rfi '^\s*Host\s+' '' <$file | string trim | string replace -r '\s+' ' ' | string split ' ' | string match -v '*\**'
|
||||||
# Extract known_host paths.
|
# Extract known_host paths.
|
||||||
set known_hosts $known_hosts (string match -ri '^\s*UserKnownHostsFile|^\s*GlobalKnownHostsFile' <$file | string replace -ri '.*KnownHostsFile\s*' '')
|
set known_hosts $known_hosts (string replace -rfi '.*KnownHostsFile\s*' '' <$file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for file in $known_hosts
|
for file in $known_hosts
|
||||||
|
|
Loading…
Reference in a new issue