From 50eba65ef8a8e310bd80f3d9d73feec63759038f Mon Sep 17 00:00:00 2001 From: Andrey Anurin Date: Wed, 15 Jan 2020 21:45:19 +0100 Subject: [PATCH] more : magic + some array args + setfacl rework --- .zprezto/abra/aliases.zsh | 19 ++++++++++ .zprezto/abra/functions.zsh | 72 +++++++++++++++++-------------------- 2 files changed, 52 insertions(+), 39 deletions(-) diff --git a/.zprezto/abra/aliases.zsh b/.zprezto/abra/aliases.zsh index 366a01f..3f16963 100644 --- a/.zprezto/abra/aliases.zsh +++ b/.zprezto/abra/aliases.zsh @@ -59,3 +59,22 @@ alias FUNCTION_PRELUDE_NO_XTRACE="setopt LOCAL_OPTIONS PIPE_FAIL NO_XTRACE ERR_R # pottering recommendation alias psc="ps xawf -eo pid,user,cgroup,args" + +local arr=( + rsync + --info=PROGRESS2 + --progress + --recursive + --compress + --human-readable + --update + --times + --no-whole-file + --itemize-changes + --stats + --verbose + --links + --no-perms + --chmod=ugo=rwX +) +alias rsync2="$arr" \ No newline at end of file diff --git a/.zprezto/abra/functions.zsh b/.zprezto/abra/functions.zsh index d54bd05..0de3b93 100644 --- a/.zprezto/abra/functions.zsh +++ b/.zprezto/abra/functions.zsh @@ -1,12 +1,21 @@ +# : magic +# ':' just evaluates the given expression +# : "${1:?dirs?}" exits saying "dirs?" if $1 is unset or null +# : "${1:=best}" sets $1 to "best" if $1 is unset or null + +# ${(j:,:)arr} joins arr with commas + + function reset_facl { FUNCTION_PRELUDE : "${1:?dirs?}" - setfacl -Rb "${@:1}" - - chown -R "root:root" "${@:1}" - chmod -R "u=rwX,g=rwX,o=" "${@:1}" + # reassign owner to root + chown --recursive "root:root" "${@:1}" + chmod --recursive "u=rwX,g=,o=" "${@:1}" + # clear facl + setfacl --recursive --remove-all "${@:1}" } function add_facl { @@ -15,12 +24,19 @@ function add_facl { : "${1:?user?}" : "${2:?dirs?}" - setfacl -Rm "\ -user:${1}:rwX,\ -default:user:${1}:rwX,\ -group:${1}:rwX,\ -default:group:${1}:rwX,\ -" "${@:2}" + local arr=( + user::rwX + user:${1}:rwX + default:user:${1}:rwX + group::0 + default:group::0 + mask::rwX + default:mask::rwX + other::0 + default:other::0 + ) + + setfacl --recursive --modify "${(j:,:)arr}" "${@:2}" } function is_local { @@ -76,14 +92,14 @@ function mount_sshfs { " | zsh -x } -function sublr { - FUNCTION_PRELUDE +# function sublr { +# FUNCTION_PRELUDE - local HOSTNAME=$(hostname) - local FULL_PATH=$(realpath $1) +# local HOSTNAME=$(hostname) +# local FULL_PATH=$(realpath $1) - echo "subl /Users/abra/mount/$HOSTNAME/$FULL_PATH" > /tmp/sshfs_command_pipe -} +# echo "subl /Users/abra/mount/$HOSTNAME/$FULL_PATH" > /tmp/sshfs_command_pipe +# } function cdtmp { FUNCTION_PRELUDE @@ -107,10 +123,7 @@ function cdtmp { function mkcd { FUNCTION_PRELUDE_NO_XTRACE - if [[ -z $1 ]]; then - echo ':(' - return 1 - fi + : "${1:?where?}" if [[ -e $1 ]]; then echo "file exists" @@ -196,25 +209,6 @@ function beet_comments { levi_beet modify \'"comments=$2"\' \'"albumartist::$1"\' } -function rsync2 { - rsync \ - --info=PROGRESS2 \ - --progress \ - --recursive \ - --compress \ - --human-readable \ - --update \ - --times \ - --no-whole-file \ - --itemize-changes \ - --stats \ - --verbose \ - --links \ - --no-perms \ - --chmod=ugo=rwX \ - "${(@)@}" -} - function sync_music { FUNCTION_PRELUDE