From 4437e8d8d6e45debb82bafaee89d64ac16b2d6c3 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 5 Sep 2017 16:29:57 +0200 Subject: [PATCH] __fish_print_hostnames: Use `string replace -f` Saves one `string match` invocation. Also removes a useless-use-of-cat. --- share/functions/__fish_print_hostnames.fish | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/share/functions/__fish_print_hostnames.fish b/share/functions/__fish_print_hostnames.fish index efa3cac4f..9d1895515 100644 --- a/share/functions/__fish_print_hostnames.fish +++ b/share/functions/__fish_print_hostnames.fish @@ -53,13 +53,13 @@ function __fish_print_hostnames -d "Print a list of known hostnames" set -l orig_dir $PWD set -l paths for config in $argv - set paths $paths (cat $config ^/dev/null \ - # Keep only Include lines - | string match -r -i '^\s*Include\s+.+' \ - # Remove Include syntax - | string replace -r -i '^\s*Include\s+' '' \ - # Normalize whitespace - | string trim | string replace -r -a '\s+' ' ') + if test -r "$config" + set paths $paths ( + # Keep only Include lines and remove Include syntax + string replace -rfi '^\s*Include\s+' '' <$config \ + # Normalize whitespace + | string trim | string replace -r -a '\s+' ' ') + end end builtin cd $relative_path @@ -89,9 +89,9 @@ function __fish_print_hostnames -d "Print a list of known hostnames" for file in $ssh_configs if test -r $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. - 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 for file in $known_hosts