diff options
Diffstat (limited to '.config/bash/rc.d/10_aliases.sh')
-rw-r--r-- | .config/bash/rc.d/10_aliases.sh | 79 |
1 files changed, 46 insertions, 33 deletions
diff --git a/.config/bash/rc.d/10_aliases.sh b/.config/bash/rc.d/10_aliases.sh index 1b25f93..de30c91 100644 --- a/.config/bash/rc.d/10_aliases.sh +++ b/.config/bash/rc.d/10_aliases.sh @@ -62,6 +62,14 @@ if [ -x "`which dircolors`" ]; then command diff "$@" fi } + + diffstat() { + if [[ -t 1 ]]; then + command diffstat -C "$@" + else + command diffstat "$@" + fi + } else alias ls='ls -1v' alias dir='dir -v' @@ -79,7 +87,6 @@ alias l='ls -CF' # Some preferences for miscellaneous stuff # ###################################################################### #alias rm='gvfs-trash' -#alias sed='sed --follow-symlinks' # breaks operating on stdio in GNU sed 4.2.2 alias tree='tree --charset utf8' alias cd=pushd alias gitk='gitk --all --date-order' @@ -98,42 +105,48 @@ term-title() { printf "$fmt" "$*" } mvln() { - local target link - if [[ ! -L "$1" ]]; then - libremessages error 'Not a soft link: %s' "$1" - return 1 - fi - if [[ -d "$2" ]]; then - link="$2/${1##*/}" - else - link="$2" - fi - target=$(readlink -f -- "$1") || return 1 - ln -srT -- "$target" "$link" - if cmp -- "$1" "$link"; then - rm -f -- "$1" - else - libremessages error 'Failed moving link: %s -> %s' "$1" "$link" - return 1 - fi + local name=mvln + local verbing=moving + _cpln "$@" } cpln() { - local target link - if [[ ! -L "$1" ]]; then - libremessages error 'Not a soft link: %s' "$1" - return 1 - fi - if [[ -d "$2" ]]; then - link="$2/${1##*/}" - else - link="$2" - fi - target=$(readlink -f -- "$1") || return 1 - ln -srT -- "$target" "$link" - if ! cmp -- "$1" "$link"; then - libremessages error 'Failed copying link: %s -> %s' "$1" "$link" + local name=cpln + local verbing=copying + _cpln "$@" +} +_cpln() { + if [[ $# -lt 2 ]]; then + libremessages error 'Usage: %s FILES... DEST' "$name" return 1 fi + declare -i i=1 + while [[ $i -lt $# ]]; do + local src dst target link + src="${!i}" + dst="${!#}" + if [[ ! -L "$src" ]]; then + libremessages error 'Not a soft link: %s' "$src" + return 1 + fi + if [[ -d "$dst" ]]; then + link="$dst/${1##*/}" + else + link="$dst" + fi + target=$(readlink -f -- "$src") || return 1 + ln -srT -- "$target" "$link" + # using `cmp` instead of `[ "$src" -ef "$link" ]` has + # the use-case where "$link" was a pre-existing link + # to a duplicate of "$src". + if ! cmp -- "$src" "$link"; then + libremessages error 'Failed %s link: %s -> %s' "$verbing" "$src" "$link" + return 1 + fi + if [[ "$name" = mvln ]]; then + rm -f -- "$src" + fi + i+=1 + done } jarls() { jar tf "$1" | |