aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/functions
diff options
context:
space:
mode:
authorGravatar Aaron Gyes <me@aaron.gy>2016-04-08 10:46:51 +0800
committerGravatar David Adam <zanchey@ucc.gu.uwa.edu.au>2016-04-08 10:49:29 +0800
commit36691df6fe4667645b71b550ce5eea90762ac23a (patch)
treeec2d420e797298da5fd83e4ee514f9643b231835 /share/functions
parent790c7f80c7d0fa1c97380885201eb50a2abcce02 (diff)
Stringify many completions and functions, with --invert stringification.
I believe apm must have been buggy - example output that I found online showed `tr` was mangling paths with spaces in it. Should be fixed. Also, use dscl on OS X in __fish_complete_users.fish like __fish_print_users.fish already does.
Diffstat (limited to 'share/functions')
-rw-r--r--share/functions/__fish_complete_pids.fish4
-rw-r--r--share/functions/__fish_complete_users.fish6
-rw-r--r--share/functions/__fish_complete_wvdial_peers.fish6
-rw-r--r--share/functions/__fish_git_prompt.fish4
-rw-r--r--share/functions/__fish_paginate.fish2
-rw-r--r--share/functions/__fish_print_abook_emails.fish2
-rw-r--r--share/functions/__fish_print_hostnames.fish4
-rw-r--r--share/functions/__fish_print_pacman_repos.fish2
-rw-r--r--share/functions/__fish_print_users.fish4
9 files changed, 18 insertions, 16 deletions
diff --git a/share/functions/__fish_complete_pids.fish b/share/functions/__fish_complete_pids.fish
index 65ba4794..e974ed61 100644
--- a/share/functions/__fish_complete_pids.fish
+++ b/share/functions/__fish_complete_pids.fish
@@ -1,11 +1,11 @@
function __fish_complete_pids -d "Print a list of process identifiers along with brief descriptions"
# This may be a bit slower, but it's nice - having the tty displayed is really handy
# 'tail -n +2' deletes the first line, which contains the headers
- # 'grep -v...' removes self from the output
+ # %self is removed from output by string match -r -v
set -l SELF %self
# Display the tty if available
# But not if it's just question marks, meaning no tty
- ps axc -o pid,ucomm,tty | grep -v '^\s*'$SELF'\s' | tail -n +2 | string replace -r ' *([0-9]+) +([^ ].*[^ ]|[^ ]) +([^ ]+) *$' '$1\t$2 [$3]' | string replace -r ' *\[\?*\] *$' ''
+ ps axc -o pid,ucomm,tty | string match -r -v '^\s*'$SELF'\s' | tail -n +2 | string replace -r ' *([0-9]+) +([^ ].*[^ ]|[^ ]) +([^ ]+) *$' '$1\t$2 [$3]' | string replace -r ' *\[\?*\] *$' ''
end
diff --git a/share/functions/__fish_complete_users.fish b/share/functions/__fish_complete_users.fish
index 91c254da..199231be 100644
--- a/share/functions/__fish_complete_users.fish
+++ b/share/functions/__fish_complete_users.fish
@@ -1,8 +1,10 @@
function __fish_complete_users --description "Print a list of local users, with the real user name as a description"
if test -x /usr/bin/getent
- getent passwd | cut -d : -f 1,5 | sed 's/:/\t/'
+ getent passwd | cut -d : -f 1,5 | string replace -r ':' \t
+ else if test -x /usr/bin/dscl
+ dscl . -list /Users RealName | string match -r -v '^_' | string replace -r ' {2,}' \t
else
- __fish_sgrep -ve '^#' /etc/passwd | cut -d : -f 1,5 | sed 's/:/\t/'
+ string match -v -r '^\s*#' < /etc/passwd | cut -d : -f 1,5 | string replace ':' \t
end
end
diff --git a/share/functions/__fish_complete_wvdial_peers.fish b/share/functions/__fish_complete_wvdial_peers.fish
index 11155b1e..5eab088b 100644
--- a/share/functions/__fish_complete_wvdial_peers.fish
+++ b/share/functions/__fish_complete_wvdial_peers.fish
@@ -15,15 +15,15 @@ function __fish_complete_wvdial_peers --description 'Complete wvdial peers' --ar
case -C --config
set store_next true
case '--config=*'
- set cfgfiles (echo $opt | sed 's/--config=//')
+ set cfgfiles (echo $opt | string replace '--config=' '')
end
end
for file in $cfgfiles
if test -f $file
- cat $file | grep '\[Dialer' | sed 's/\[Dialer \(.\+\)\]/\1/'
+ string match -r '\[Dialer' < $file | string replace -r '\[Dialer (.+)\]' '$1'
end
- end | sort -u | grep -v Defaults
+ end | sort -u | string match -v Defaults
end
diff --git a/share/functions/__fish_git_prompt.fish b/share/functions/__fish_git_prompt.fish
index 4fb2f16c..128a3f97 100644
--- a/share/functions/__fish_git_prompt.fish
+++ b/share/functions/__fish_git_prompt.fish
@@ -286,8 +286,8 @@ function __fish_git_prompt_show_upstream --description "Helper function for __fi
set -l os
set -l commits (command git rev-list --left-right $upstream...HEAD ^/dev/null; set os $status)
if test $os -eq 0
- set -l behind (count (for arg in $commits; echo $arg; end | grep '^<'))
- set -l ahead (count (for arg in $commits; echo $arg; end | grep -v '^<'))
+ set -l behind (count (for arg in $commits; echo $arg; end | string match -r '^<'))
+ set -l ahead (count (for arg in $commits; echo $arg; end | string match -r -v '^<'))
set count "$behind $ahead"
else
set count
diff --git a/share/functions/__fish_paginate.fish b/share/functions/__fish_paginate.fish
index 7887cf6b..31cdd61f 100644
--- a/share/functions/__fish_paginate.fish
+++ b/share/functions/__fish_paginate.fish
@@ -5,7 +5,7 @@ function __fish_paginate -d "Paginate the current command using the users defaul
set cmd $PAGER
end
- if commandline -j|grep -v "$cmd *\$" >/dev/null
+ if commandline -j| string match -q -r -v "$cmd *\$"
commandline -aj " ^&1 |$cmd;"
end
diff --git a/share/functions/__fish_print_abook_emails.fish b/share/functions/__fish_print_abook_emails.fish
index c1a8d294..f32b2aed 100644
--- a/share/functions/__fish_print_abook_emails.fish
+++ b/share/functions/__fish_print_abook_emails.fish
@@ -1,4 +1,4 @@
function __fish_print_abook_emails --description 'Print email addresses (abook)'
- abook --mutt-query "" | egrep -v '^\s*$'
+ abook --mutt-query "" | string match -r -v '^\s*$'
end
diff --git a/share/functions/__fish_print_hostnames.fish b/share/functions/__fish_print_hostnames.fish
index 38515776..40499d1e 100644
--- a/share/functions/__fish_print_hostnames.fish
+++ b/share/functions/__fish_print_hostnames.fish
@@ -5,11 +5,11 @@ function __fish_print_hostnames -d "Print a list of known hostnames"
# Print all hosts from /etc/hosts
if type -q getent
# Ignore zero ips
- getent hosts | grep -v '^0.0.0.0' \
+ getent hosts | string match -r -v '^0.0.0.0' \
| string replace -r '[0-9.]*\s*' '' | string split " "
else if test -r /etc/hosts
# Ignore commented lines and functionally empty lines
- grep -v '^\s*0.0.0.0\|^\s*#\|^\s*$' /etc/hosts \
+ string match -r -v '^\s*0.0.0.0|^\s*#|^\s*$' < /etc/hosts \
# Strip comments
| string replace -ra '#.*$' '' \
| string replace -r '[0-9.]*\s*' '' | string trim | string replace -ra '\s+' '\n'
diff --git a/share/functions/__fish_print_pacman_repos.fish b/share/functions/__fish_print_pacman_repos.fish
index 81fe3de5..1998f721 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"
- sed -n -e 's/\[\(.\+\)\]/\1/p' /etc/pacman.conf | grep -v "#\|options"
+ string replace -r -a "\[(.+)\]" "\1" < /etc/pacman.conf | string match -r -v "^#|options"
end
diff --git a/share/functions/__fish_print_users.fish b/share/functions/__fish_print_users.fish
index f6d41fa9..d2915760 100644
--- a/share/functions/__fish_print_users.fish
+++ b/share/functions/__fish_print_users.fish
@@ -3,9 +3,9 @@ function __fish_print_users --description "Print a list of local users"
if test -x /usr/bin/getent
getent passwd | cut -d : -f 1
else if test -x /usr/bin/dscl # OS X support
- dscl . -list /Users | __fish_sgrep -v '^_'
+ dscl . -list /Users | string match -r -v '^_'
else
- __fish_sgrep -ve '^#' /etc/passwd | cut -d : -f 1
+ string match -v -r '^\w*#' < /etc/passwd | cut -d : -f 1
end
end