mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 04:58:57 +00:00
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.
This commit is contained in:
parent
790c7f80c7
commit
36691df6fe
17 changed files with 35 additions and 31 deletions
|
@ -61,7 +61,7 @@ end
|
|||
|
||||
# Lists all apm config items
|
||||
function __fish_apm_config_items
|
||||
apm config list | grep -v '^;\|^$' | tr "\ =\ " "\t"
|
||||
apm config list | string match -r -v "^\s*;|^\s*\$" | string replace "\w*=\w*" \t
|
||||
end
|
||||
|
||||
# Lists all installed atom packages
|
||||
|
@ -69,7 +69,7 @@ function __fish_apm_list_packages
|
|||
apm list -b
|
||||
end
|
||||
|
||||
if apm -h ^| grep -q "Atom Package Manager"
|
||||
if apm -h ^| string match -q "Atom Package Manager*"
|
||||
# Completions for Atom Package Manager
|
||||
|
||||
##################
|
||||
|
|
|
@ -11,13 +11,13 @@ function __fish_git_commits
|
|||
end
|
||||
|
||||
function __fish_git_branches
|
||||
command git branch --no-color -a ^/dev/null | __fish_sgrep -v ' -> ' | string trim -c "* " | string replace -r "^remotes/" ""
|
||||
command git branch --no-color -a ^/dev/null | string match -r -v ' -> ' | string trim -c "* " | string replace -r "^remotes/" ""
|
||||
end
|
||||
|
||||
function __fish_git_unique_remote_branches
|
||||
# Allow all remote branches with one remote without the remote part
|
||||
# This is useful for `git checkout` to automatically create a remote-tracking branch
|
||||
command git branch --no-color -a ^/dev/null | __fish_sgrep -v ' -> ' | string trim -c "* " | string replace -r "^remotes/[^/]*/" "" | sort | uniq -u
|
||||
command git branch --no-color -a ^/dev/null | string match -r -v ' -> ' | string trim -c "* " | string replace -r "^remotes/[^/]*/" "" | sort | uniq -u
|
||||
end
|
||||
|
||||
function __fish_git_tags
|
||||
|
@ -473,7 +473,7 @@ complete -f -c git -n '__fish_git_using_command status' -l ignore-submodules -x
|
|||
|
||||
### tag
|
||||
complete -f -c git -n '__fish_git_needs_command' -a tag -d 'Create, list, delete or verify a tag object signed with GPG'
|
||||
complete -f -c git -n '__fish_git_using_command tag; and __fish_not_contain_opt -s d; and __fish_not_contain_opt -s v; and test (count (commandline -opc | __fish_sgrep -v -e \'^-\')) -eq 3' -a '(__fish_git_branches)' -d 'Branch'
|
||||
complete -f -c git -n '__fish_git_using_command tag; and __fish_not_contain_opt -s d; and __fish_not_contain_opt -s v; and test (count (commandline -opc | string match -r -v \'^-\')) -eq 3' -a '(__fish_git_branches)' -d 'Branch'
|
||||
complete -f -c git -n '__fish_git_using_command tag' -s a -l annotate -d 'Make an unsigned, annotated tag object'
|
||||
complete -f -c git -n '__fish_git_using_command tag' -s s -l sign -d 'Make a GPG-signed tag'
|
||||
complete -f -c git -n '__fish_git_using_command tag' -s d -l delete -d 'Remove a tag'
|
||||
|
|
|
@ -47,6 +47,8 @@ function __fish_print_gpg_algo -d "Complete using all algorithms of the type spe
|
|||
# expire when the function goes out of scope, and the original locale
|
||||
# will take effect again.
|
||||
set -lx LC_ALL C
|
||||
|
||||
# XXX this misses certain ciphers in gpg --version - redo this entirely and use fish's annoying group printing as a feature finally!
|
||||
gpg --version | __fish_sgrep "$argv:"| __fish_sgrep -v "Home:"|cut -d : -f 2 |tr , \n|tr -d " "
|
||||
end
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ complete -f -c npm -n 'not __fish_npm_needs_option' -a "(__fish_complete_npm)"
|
|||
|
||||
# list available npm scripts and their parial content
|
||||
function __fish_npm_run
|
||||
command npm run | command grep -v '^[^ ]' | command grep -v '^$' | command sed "s/^ *//" | while read -l name
|
||||
command npm run | string match -r -v '^[^ ]|^$' | string trim | while read -l name
|
||||
set -l trim 20
|
||||
read -l value
|
||||
echo "$value" | cut -c1-$trim | read -l value
|
||||
|
|
|
@ -49,13 +49,13 @@ for line in $rust_docs
|
|||
end
|
||||
|
||||
set -l rust_docs (rustc -W help \
|
||||
| egrep \
|
||||
'(\s+)(.+)(\s+)(allow|warn|deny|forbid)(\s+){2}([^\n]+)' \
|
||||
| string match -r \
|
||||
'(?:\s+)(?:.+)(?:\s+)(?:allow|warn|deny|forbid)(?:\s+){2}(?:[^\n]+)' \
|
||||
| string replace -r -i \
|
||||
'(\s+)(.+)(\s+)(allow|warn|deny|forbid)(\s+){2}([^\n]+)' '$2 $6' \
|
||||
| string match -r '^.*[^:]$' \
|
||||
| egrep -v '^(allow|warn|deny|forbid)$' \
|
||||
| egrep -v '^([a-z\-]+)(\s+)(allow|warn|deny|forbid)')
|
||||
| string match -r -v '^(allow|warn|deny|forbid)$' \
|
||||
| string match -r -v '^([a-z\-]+)(\s+)(allow|warn|deny|forbid)')
|
||||
|
||||
for line in $rust_docs
|
||||
set docs (string split -m 1 ' ' $line)
|
||||
|
|
|
@ -15,7 +15,7 @@ complete -x -c ssh -d Hostname -a "
|
|||
"
|
||||
|
||||
complete -x -c ssh -d User -a "
|
||||
(__fish_print_users | __fish_sgrep -v '^_')@
|
||||
(__fish_print_users | string match -r -v '^_')@
|
||||
"
|
||||
complete -c ssh --description "Command to run" -x -a '(__fish_complete_subcommand --fcs-skip=2)'
|
||||
|
||||
|
@ -23,7 +23,7 @@ complete -c ssh -s a --description "Disables forwarding of the authentication ag
|
|||
complete -c ssh -s A --description "Enables forwarding of the authentication agent"
|
||||
complete -x -c ssh -s b --description "Interface to transmit from" -a "
|
||||
(
|
||||
cat /proc/net/arp ^/dev/null| __fish_sgrep -v '^IP'|cut -d ' ' -f 1 ^/dev/null
|
||||
cat /proc/net/arp ^/dev/null| string match -r -v '^IP'|cut -d ' ' -f 1 ^/dev/null
|
||||
)
|
||||
"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ function fish_prompt -d "Write out the prompt"
|
|||
if [ (_git_branch_name) ]
|
||||
set -l git_branch (set_color -o blue)(_git_branch_name)
|
||||
if [ (_is_git_dirty) ]
|
||||
for i in (git branch -qv --no-color|grep \*|cut -d' ' -f4-|cut -d] -f1|tr , \n)\
|
||||
for i in (git branch -qv --no-color| string match -r \*|cut -d' ' -f4-|cut -d] -f1|tr , \n)\
|
||||
(git status --porcelain | cut -c 1-2 | uniq)
|
||||
switch $i
|
||||
case "*[ahead *"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
function fish_prompt
|
||||
and set retc green; or set retc red
|
||||
tty|grep -q tty; and set tty tty; or set tty pts
|
||||
tty|string match -q -r tty; and set tty tty; or set tty pts
|
||||
|
||||
set_color $retc
|
||||
if [ $tty = tty ]
|
||||
|
@ -48,7 +48,7 @@ function fish_prompt
|
|||
echo -n ]
|
||||
|
||||
if type -q acpi
|
||||
if [ (acpi -a 2> /dev/null | grep off) ]
|
||||
if [ (acpi -a 2> /dev/null | string match -r off) ]
|
||||
echo -n '─['
|
||||
set_color -o red
|
||||
echo -n (acpi -b|cut -d' ' -f 4-)
|
||||
|
|
Loading…
Reference in a new issue