mirror of
https://github.com/dcarrillo/prezto.git
synced 2024-12-22 23:08:00 +00:00
[utility] Refactor rsync_scp wrapper function and add completion support
Changes: - Rename `rsync_scp_wrap` to `noremoteglob` and make it more generally usable - Enable completion support for commands wrapped with `noremoteglob` - Tighten up internal variable usages - Update documentation for 'noremoteglob' function
This commit is contained in:
parent
17a59bada7
commit
a60fe47359
@ -65,8 +65,8 @@ Aliases
|
|||||||
- `history`
|
- `history`
|
||||||
- `locate`
|
- `locate`
|
||||||
- `rake`
|
- `rake`
|
||||||
- `rsync`
|
- `rsync` (selectively enabled for local files)
|
||||||
- `scp`
|
- `scp` (selectively enabled for local files)
|
||||||
- `sftp`
|
- `sftp`
|
||||||
|
|
||||||
### General
|
### General
|
||||||
@ -149,6 +149,7 @@ Functions
|
|||||||
- `mkdcd` makes a directory and changes to it.
|
- `mkdcd` makes a directory and changes to it.
|
||||||
- `popdls` pops an entry off the directory stack and lists its contents.
|
- `popdls` pops an entry off the directory stack and lists its contents.
|
||||||
- `pushdls` pushes an entry onto the directory stack and lists its contents.
|
- `pushdls` pushes an entry onto the directory stack and lists its contents.
|
||||||
|
- `noremoteglob` enable local path globbing but disable remote path globbing.
|
||||||
|
|
||||||
### Developer
|
### Developer
|
||||||
|
|
||||||
|
11
modules/utility/functions/_noremoteglob
Normal file
11
modules/utility/functions/_noremoteglob
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#compdef noremoteglob
|
||||||
|
#autoload
|
||||||
|
|
||||||
|
#
|
||||||
|
# Completes noremoteglob.
|
||||||
|
#
|
||||||
|
# Authors:
|
||||||
|
# Indrajit Raychaudhuri <irc+code@indrajit.com>
|
||||||
|
#
|
||||||
|
|
||||||
|
_precommand
|
@ -41,33 +41,8 @@ alias ftp='noglob ftp'
|
|||||||
alias history='noglob history'
|
alias history='noglob history'
|
||||||
alias locate='noglob locate'
|
alias locate='noglob locate'
|
||||||
alias rake='noglob rake'
|
alias rake='noglob rake'
|
||||||
alias rsync='noglob rsync_wrap'
|
alias rsync='noglob noremoteglob rsync'
|
||||||
alias scp='noglob scp_wrap'
|
alias scp='noglob noremoteglob scp'
|
||||||
# This function wraps rsync and scp so that remote paths are not globbed
|
|
||||||
# but local paths are globbed. This is because the programs have their own
|
|
||||||
# globbing for remote paths. The wrap function globs args starting in / and ./
|
|
||||||
# and doesn't glob paths with : in it as these are interpreted as remote paths
|
|
||||||
# by these programs unless the path starts with / or ./
|
|
||||||
function rsync_scp_wrap {
|
|
||||||
local args=( )
|
|
||||||
local cmd="$1"
|
|
||||||
shift
|
|
||||||
local i
|
|
||||||
for i in "$@"; do case $i in
|
|
||||||
( ./* ) args+=( ${~i} ) ;; # glob
|
|
||||||
( /* ) args+=( ${~i} ) ;; # glob
|
|
||||||
( *:* ) args+=( ${i} ) ;; # noglob
|
|
||||||
( * ) args+=( ${~i} ) ;; # glob
|
|
||||||
esac; done
|
|
||||||
command $cmd "${(@)args}"
|
|
||||||
}
|
|
||||||
function rsync_wrap {
|
|
||||||
rsync_scp_wrap "rsync" "$@"
|
|
||||||
}
|
|
||||||
function scp_wrap {
|
|
||||||
rsync_scp_wrap "scp" "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
alias sftp='noglob sftp'
|
alias sftp='noglob sftp'
|
||||||
|
|
||||||
# Define general aliases.
|
# Define general aliases.
|
||||||
@ -239,3 +214,23 @@ function find-exec {
|
|||||||
function psu {
|
function psu {
|
||||||
ps -U "${1:-$LOGNAME}" -o 'pid,%cpu,%mem,command' "${(@)argv[2,-1]}"
|
ps -U "${1:-$LOGNAME}" -o 'pid,%cpu,%mem,command' "${(@)argv[2,-1]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Enables globbing selectively on path arguments.
|
||||||
|
# Globbing is enabled on local paths (starting in '/' and './') and disabled
|
||||||
|
# on remote paths (containing ':' but not starting in '/' and './'). This is
|
||||||
|
# useful for programs that have their own globbing for remote paths.
|
||||||
|
# Currently, this is used by default for 'rsync' and 'scp'.
|
||||||
|
# Example:
|
||||||
|
# - Local: '*.txt', './foo:2017*.txt', '/var/*:log.txt'
|
||||||
|
# - Remote: user@localhost:foo/
|
||||||
|
function noremoteglob {
|
||||||
|
local -a argo
|
||||||
|
local cmd="$1"
|
||||||
|
for arg in ${argv:2}; do case $arg in
|
||||||
|
( ./* ) argo+=( ${~arg} ) ;; # local relative, glob
|
||||||
|
( /* ) argo+=( ${~arg} ) ;; # local absolute, glob
|
||||||
|
( *:* ) argo+=( ${arg} ) ;; # remote, noglob
|
||||||
|
( * ) argo+=( ${~arg} ) ;; # default, glob
|
||||||
|
esac; done
|
||||||
|
command $cmd "${(@)argo}"
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user