From 51da7120402336dd109023d87df2eba632374423 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Sun, 4 Jul 2021 21:56:12 +0200 Subject: [PATCH] bin/bak: improve suffix handling --- .config/shell/functions | 1 + .local/bin/scripts/bak | 9 ++++++++- .local/bin/scripts/st | 5 ++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.config/shell/functions b/.config/shell/functions index 365af5d..3a49724 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -139,6 +139,7 @@ alias tw='timew' twsm() { timew summary $(date --date="Monday $1 week ago" -I) to tomorrow :ids ${@:2} } alias twtest='( cp -r "$TIMEWARRIORDB" /tmp/tw-bak && TIMEWARRIORDB=/tmp/timewarriordb-test/$(date +%s) && mkdir -p "$TIMEWARRIORDB"/data && :> "$TIMEWARRIORDB"/timewarrior.cfg && $SHELL )' +alias expr='noglob expr' alias lst='( last; last -f /var/log/wtmp.1 ) | grep -v "pts/" | tac | less +G' alias lar='last | tac' diff --git a/.local/bin/scripts/bak b/.local/bin/scripts/bak index 24ddead..2e1119d 100755 --- a/.local/bin/scripts/bak +++ b/.local/bin/scripts/bak @@ -1,3 +1,10 @@ #!/bin/sh suffix="${2:-bak}" -test -e "$1.$suffix" && ((test -e "$1" && mv -v "$1" /tmp); mv -vn "$1.$suffix" "$1") || mv -vn "$1" "$1.$suffix" +orig="${1%%.$suffix}" +echo $orig +if test -e "$orig.$suffix" +then + test -e "$orig" && mv -v "$orig" /tmp + mv -vn "$orig.$suffix" "$orig" +else mv -vn "$1" "$1.$suffix" +fi diff --git a/.local/bin/scripts/st b/.local/bin/scripts/st index bc0e111..6dc843f 100755 --- a/.local/bin/scripts/st +++ b/.local/bin/scripts/st @@ -5,8 +5,11 @@ if test -f "$subscript" then shift && $subscript "$@" else apikey=$(grep apikey $XDG_CONFIG_HOME/syncthing/config.xml | cut -d '>' -f2 | cut -d '<' -f1) + parseargs() { + echo hi + } case "$1" in - (browse|need) + (browse|completion|file|ignores|need|status) for arg in "${@:2}" do case "$arg" in ([0-9]) depth=$arg;; (*) path="$arg";; esac done