diff options
Diffstat (limited to 'hm/soispha/conf/lf/commands/scripts/cow_cp.sh')
-rwxr-xr-x | hm/soispha/conf/lf/commands/scripts/cow_cp.sh | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/hm/soispha/conf/lf/commands/scripts/cow_cp.sh b/hm/soispha/conf/lf/commands/scripts/cow_cp.sh index 85fd3431..c17b7668 100755 --- a/hm/soispha/conf/lf/commands/scripts/cow_cp.sh +++ b/hm/soispha/conf/lf/commands/scripts/cow_cp.sh @@ -1,8 +1,17 @@ -#!/usr/bin/env dash +#!/usr/bin/env bash # shellcheck source=/dev/null SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +fx="$fx" +# shellcheck disable=SC2269 +fs="$fs" +# shellcheck disable=SC2269 +id="$id" + # source: https://github.com/gokcehan/lf/wiki/Tips#use-copy-on-write-when-possible # # # FIXME: Add this. The hardest part is in checking, if a file can be reflinked, as fuse and bind mount are hard to @@ -31,13 +40,13 @@ if [ "$mode" = 'copy' ]; then src_targets="$(df --output=target -- "$@" | sed '1d' | sort -u)" if [ "$(df --output=target -- "$PWD" | tail -n 1)" = \ - "$(echo "$src_targets" | tail -n 1)" ] && \ - (( "$(echo "$src_targets" | wc -l)" == 1 )) && \ + "$(echo "$src_targets" | tail -n 1)" ] && + (("$(echo "$src_targets" | wc -l)" == 1)) && [[ "$(df --output=fstype -- "$PWD" | tail -n 1)" =~ ^(btrfs|xfs|zfs)$ ]]; then - echo 'selected copy and cp reflink paste' + echo 'selected copy and cp reflink paste' - start=$(date '+%s') + start=$(date '+%s') # Handle same names in dst # TODO parallelism, idk - but exit/return/break won't stop the loop from subshell... @@ -47,7 +56,7 @@ if [ "$mode" = 'copy' ]; then count=0 while [ -w "$PWD/$name" ]; do - count=$((count+1)) + count=$((count + 1)) name="$original.~$count~" done @@ -55,15 +64,15 @@ if [ "$mode" = 'copy' ]; then cp_out="$(cp -rn --reflink=always -- "$i" "$PWD/$name" 2>&1)" set -e - if [ ! -z "$cp_out" ]; then + if [ -n "$cp_out" ]; then lf -remote "send $id echoerr $cp_out" exit 0 fi done - finish=$(( $(date '+%s') - $start )) + finish=$(($(date '+%s') - start)) t='' - if (( $finish > 2 )); then + if ((finish > 2)); then t="${finish}s" fi @@ -80,14 +89,14 @@ if [ "$mode" = 'copy' ]; then echo 'selected copy and lf native paste' lf -remote "send $id paste" lf -remote "send clear" - fi - - elif [ $mode = 'move' ]; then - echo 'selected move and lf native paste' - lf -remote "send $id paste" - lf -remote "send clear" fi +elif [ "$mode" = 'move' ]; then + echo 'selected move and lf native paste' + lf -remote "send $id paste" + lf -remote "send clear" +fi + # # for debug # set +x |