Full namespace add to simple functions

This commit is contained in:
Sebastian Gniazdowski 2017-09-21 13:14:20 +02:00
parent 1aa961317c
commit 0808de2992
5 changed files with 38 additions and 38 deletions

26
zc
View file

@ -1,8 +1,8 @@
setopt localoptions extendedglob clobber setopt localoptions extendedglob clobber
function __zconvey_usage_zc() { function __zconvey_usage_zc() {
pinfo2 "Sends specified commands to given (via ID or NAME) Zsh session" __zconvey_pinfo2 "Sends specified commands to given (via ID or NAME) Zsh session"
pinfo "Usage: zc {-i ID}|{-n NAME} [-q|--quiet] [-v|--verbose] [-h|--help] [-a|--ask] [-r|--raw] COMMAND ARGUMENT ..." __zconvey_pinfo "Usage: zc {-i ID}|{-n NAME} [-q|--quiet] [-v|--verbose] [-h|--help] [-a|--ask] [-r|--raw] COMMAND ARGUMENT ..."
print -- "-h/--help - this message" print -- "-h/--help - this message"
print -- "-i ID / --id ID - ID (number) of Zsh session" print -- "-i ID / --id ID - ID (number) of Zsh session"
print -- "-n NAME / --name NAME - NAME of Zsh session" print -- "-n NAME / --name NAME - NAME of Zsh session"
@ -45,12 +45,12 @@ fi
(( raw = ${+opthash[-r]} + ${+opthash[--raw]} )) (( raw = ${+opthash[-r]} + ${+opthash[--raw]} ))
if [[ "$have_id" != "0" && "$have_name" != "0" ]]; then if [[ "$have_id" != "0" && "$have_name" != "0" ]]; then
pinfo "Please supply only one of ID (-i) and NAME (-n)" __zconvey_pinfo "Please supply only one of ID (-i) and NAME (-n)"
return 1 return 1
fi fi
if [[ "$have_id" != "0" && "$id" != <-> ]]; then if [[ "$have_id" != "0" && "$id" != <-> ]]; then
pinfo "ID must be numeric, 1..100" __zconvey_pinfo "ID must be numeric, 1..100"
return 1 return 1
fi fi
@ -75,7 +75,7 @@ if [[ -z "$cmd" && "$ask" = "0" ]]; then
fi fi
if [[ "$have_id" = "0" && "$have_name" = "0" && "$ask" = "0" ]]; then if [[ "$have_id" = "0" && "$have_name" = "0" && "$ask" = "0" ]]; then
pinfo "Either supply target ID/NAME or request Zsh-Select (-a/--ask)" __zconvey_pinfo "Either supply target ID/NAME or request Zsh-Select (-a/--ask)"
return 1 return 1
fi fi
@ -101,7 +101,7 @@ if (( $ask )); then
cmd="${cmd##[[:space:]]#}" cmd="${cmd##[[:space:]]#}"
cmd="${cmd%%[[:space:]]#}" cmd="${cmd%%[[:space:]]#}"
if [ -z "$cmd" ]; then if [ -z "$cmd" ]; then
pinfo "No command enterred, exiting" __zconvey_pinfo "No command enterred, exiting"
return 0 return 0
fi fi
fi fi
@ -109,14 +109,14 @@ if (( $ask )); then
# Supply session? # Supply session?
if [[ "$have_id" = "0" && "$have_name" = "0" ]]; then if [[ "$have_id" = "0" && "$have_name" = "0" ]]; then
if ! type zsh-select 2>/dev/null 1>&2; then if ! type zsh-select 2>/dev/null 1>&2; then
pinfo "Zsh-Select not installed, please install it before using -a/--ask, aborting" __zconvey_pinfo "Zsh-Select not installed, please install it before using -a/--ask, aborting"
pinfo "Example installation: zplugin load psprint/zsh-select" __zconvey_pinfo "Example installation: zplugin load psprint/zsh-select"
return 1 return 1
else else
export ZSHSELECT_START_IN_SEARCH_MODE=0 export ZSHSELECT_START_IN_SEARCH_MODE=0
id=`zc-ls | zsh-select` id=`zc-ls | zsh-select`
if [ -z "$id" ]; then if [ -z "$id" ]; then
pinfo "No selection, exiting" __zconvey_pinfo "No selection, exiting"
return 0 return 0
else else
id="${id//(#b)*ID: ([[:digit:]]#)[^[:digit:]]#*(#e)/$match[1]}" id="${id//(#b)*ID: ([[:digit:]]#)[^[:digit:]]#*(#e)/$match[1]}"
@ -126,12 +126,12 @@ if (( $ask )); then
fi fi
if [ -z "$cmd" ]; then if [ -z "$cmd" ]; then
pinfo "No command provided, aborting" __zconvey_pinfo "No command provided, aborting"
return 1 return 1
fi fi
if [[ "$id" != <-> || "$id" = "0" || "$id" -gt "100" ]]; then if [[ "$id" != <-> || "$id" = "0" || "$id" -gt "100" ]]; then
pinfo "Incorrect sesion ID occured: \`$idx'. ID should be in range 1..100" __zconvey_pinfo "Incorrect sesion ID occured: \`$idx'. ID should be in range 1..100"
return 1 return 1
fi fi
@ -155,7 +155,7 @@ echo "PID $$ ID $ZCONVEY_ID is sending command" > "$lockfile"
if (( ${ZCONVEY_CONFIG[use_zsystem_flock]} > 0 )); then if (( ${ZCONVEY_CONFIG[use_zsystem_flock]} > 0 )); then
(( ${verbose} )) && print "Will use zsystem flock..." (( ${verbose} )) && print "Will use zsystem flock..."
if ! zsystem flock -t 2 -f fd "$lockfile"; then if ! zsystem flock -t 2 -f fd "$lockfile"; then
pinfo2 "Communication channel of session $id is busy, could not send" __zconvey_pinfo2 "Communication channel of session $id is busy, could not send"
return 1 return 1
fi fi
# 2. Provided flock binary (two calls) # 2. Provided flock binary (two calls)
@ -168,7 +168,7 @@ else
LANG=C sleep 1 LANG=C sleep 1
"${ZCONVEY_REPO_DIR}/myflock/flock" -nx "$fd" "${ZCONVEY_REPO_DIR}/myflock/flock" -nx "$fd"
if [ "$?" = "101" ]; then if [ "$?" = "101" ]; then
pinfo2 "Communication channel of session $id is busy, could not send" __zconvey_pinfo2 "Communication channel of session $id is busy, could not send"
return 1 return 1
fi fi
fi fi

10
zc-all
View file

@ -3,8 +3,8 @@ integer idx is_locked counter=0
local name busyfile busywith local name busyfile busywith
__zconvey_usage_zc-all() { __zconvey_usage_zc-all() {
pinfo2 "Sends command to all unbusy sessions (also busy when -f passed)" __zconvey_pinfo2 "Sends command to all unbusy sessions (also busy when -f passed)"
pinfo "Usage: zc-all [-h|--help] [-f|--force] [-a|--ask] [-q|--quiet] [-v|--verbose] COMMAND ARGUMENT ..." __zconvey_pinfo "Usage: zc-all [-h|--help] [-f|--force] [-a|--ask] [-q|--quiet] [-v|--verbose] COMMAND ARGUMENT ..."
print -- "-h/--help - this message" print -- "-h/--help - this message"
print -- "-q/--quiet - don't output status messages" print -- "-q/--quiet - don't output status messages"
print -- "-v/--verbose - output more status messages" print -- "-v/--verbose - output more status messages"
@ -51,14 +51,14 @@ if (( $ask )); then
cmd="${cmd##[[:space:]]#}" cmd="${cmd##[[:space:]]#}"
cmd="${cmd%%[[:space:]]#}" cmd="${cmd%%[[:space:]]#}"
if [ -z "$cmd" ]; then if [ -z "$cmd" ]; then
pinfo "No command enterred, exiting" __zconvey_pinfo "No command enterred, exiting"
return 0 return 0
fi fi
fi fi
fi fi
if [ -z "$cmd" ]; then if [ -z "$cmd" ]; then
pinfo "No command provided, aborting" __zconvey_pinfo "No command provided, aborting"
return 1 return 1
fi fi
@ -93,7 +93,7 @@ for (( idx = 1; idx <= 100; idx ++ )); do
fi fi
done done
(( quiet )) || pinfo "Sent command to $counter other sessions" (( quiet )) || __zconvey_pinfo "Sent command to $counter other sessions"
return 0 return 0

View file

@ -3,7 +3,7 @@ integer idx is_locked counter=0
local busyfile busywith local busyfile busywith
if [[ "$1" = "-h" || "$1" = "--help" ]]; then if [[ "$1" = "-h" || "$1" = "--help" ]]; then
pinfo "Sends zc-logo or zc-id to all terminals (the latter when argument \"text\" is passed)" __zconvey_pinfo "Sends zc-logo or zc-id to all terminals (the latter when argument \"text\" is passed)"
return 0 return 0
fi fi
@ -28,7 +28,7 @@ for (( idx = 1; idx <= 100; idx ++ )); do
fi fi
done done
pinfo "Sent logo request to $counter sessions, including this one" __zconvey_pinfo "Sent logo request to $counter sessions, including this one"
return 0 return 0

View file

@ -1,8 +1,8 @@
setopt localoptions extendedglob clobber setopt localoptions extendedglob clobber
function __zconvey_usage_zc-rename() { function __zconvey_usage_zc-rename() {
pinfo2 "Renames current Zsh session, or one given via ID or (old) NAME" __zconvey_pinfo2 "Renames current Zsh session, or one given via ID or (old) NAME"
pinfo "Usage: zc-rename [-i ID|-n NAME] [-q|--quiet] [-h|--help] NEW_NAME" __zconvey_pinfo "Usage: zc-rename [-i ID|-n NAME] [-q|--quiet] [-h|--help] NEW_NAME"
print -- "-h/--help - this message" print -- "-h/--help - this message"
print -- "-i ID / --id ID - ID (number) of Zsh session" print -- "-i ID / --id ID - ID (number) of Zsh session"
print -- "-n NAME / --name NAME - NAME of Zsh session" print -- "-n NAME / --name NAME - NAME of Zsh session"
@ -33,12 +33,12 @@ have_name=$(( ${+opthash[-n]} + ${+opthash[--name]} ))
(( quiet = ${+opthash[-q]} + ${+opthash[--quiet]} )) (( quiet = ${+opthash[-q]} + ${+opthash[--quiet]} ))
if [[ "$have_id" != "0" && "$have_name" != "0" ]]; then if [[ "$have_id" != "0" && "$have_name" != "0" ]]; then
pinfo "Please supply only one of ID (-i) and NAME (-n)" __zconvey_pinfo "Please supply only one of ID (-i) and NAME (-n)"
return 1 return 1
fi fi
if [[ "$have_id" != "0" && ( "$id" != <-> || "$id" = "0" ) ]]; then if [[ "$have_id" != "0" && ( "$id" != <-> || "$id" = "0" ) ]]; then
pinfo "ID must be numeric, 1..100" __zconvey_pinfo "ID must be numeric, 1..100"
return 1 return 1
fi fi
@ -47,7 +47,7 @@ if (( $have_name )); then
__zconvey_resolve_name_to_id "$name" __zconvey_resolve_name_to_id "$name"
local resolved="$REPLY" local resolved="$REPLY"
if [ -z "$resolved" ]; then if [ -z "$resolved" ]; then
pinfo "Could not find session named: \`$name'" __zconvey_pinfo "Could not find session named: \`$name'"
return 1 return 1
fi fi
@ -60,24 +60,24 @@ fi
__zconvey_resolve_name_to_id "$new_name" __zconvey_resolve_name_to_id "$new_name"
if [ -n "$REPLY" ]; then if [ -n "$REPLY" ]; then
pinfo "A session already has target name: \`$new_name' (its ID: $REPLY)" __zconvey_pinfo "A session already has target name: \`$new_name' (its ID: $REPLY)"
return 1 return 1
fi fi
if [[ "$id" != <-> || "$id" = "0" ]]; then if [[ "$id" != <-> || "$id" = "0" ]]; then
pinfo "Bad ID ($id), aborting" __zconvey_pinfo "Bad ID ($id), aborting"
return 1 return 1
fi fi
if [[ "$id" -gt "100" ]]; then if [[ "$id" -gt "100" ]]; then
pinfo "Maximum nr of sessions is 100, aborting" __zconvey_pinfo "Maximum nr of sessions is 100, aborting"
return 1 return 1
fi fi
print ":$new_name:" > "$ZCONVEY_NAMES_DIR"/"$id".name print ":$new_name:" > "$ZCONVEY_NAMES_DIR"/"$id".name
if (( ${quiet} == 0 )); then if (( ${quiet} == 0 )); then
pinfo2 "Renamed session $id to: $new_name" __zconvey_pinfo2 "Renamed session $id to: $new_name"
fi fi
local ls_after_rename local ls_after_rename

18
zc-take
View file

@ -1,9 +1,9 @@
setopt localoptions extendedglob clobber setopt localoptions extendedglob clobber
function __zconvey_usage_zc-take() { function __zconvey_usage_zc-take() {
pinfo2 "Takes a name for current Zsh session, i.e. takes it away from any other session if needed" __zconvey_pinfo2 "Takes a name for current Zsh session, i.e. takes it away from any other session if needed"
pinfo2 "You can take a name for other session (not the current one) if -i or -n is provided" __zconvey_pinfo2 "You can take a name for other session (not the current one) if -i or -n is provided"
pinfo "Usage: zc-take [-i ID|-n NAME] [-q|--quiet] [-h|--help] NEW_NAME" __zconvey_pinfo "Usage: zc-take [-i ID|-n NAME] [-q|--quiet] [-h|--help] NEW_NAME"
print -- "-h/--help - this message" print -- "-h/--help - this message"
print -- "-i ID / --id ID - ID (number) of Zsh session" print -- "-i ID / --id ID - ID (number) of Zsh session"
print -- "-n NAME / --name NAME - NAME of Zsh session" print -- "-n NAME / --name NAME - NAME of Zsh session"
@ -34,12 +34,12 @@ have_name=$(( ${+opthash[-n]} + ${+opthash[--name]} ))
(( quiet = ${+opthash[-q]} + ${+opthash[--quiet]} )) (( quiet = ${+opthash[-q]} + ${+opthash[--quiet]} ))
if [[ "$have_id" != "0" && "$have_name" != "0" ]]; then if [[ "$have_id" != "0" && "$have_name" != "0" ]]; then
pinfo "Please supply only one of ID (-i) and NAME (-n)" __zconvey_pinfo "Please supply only one of ID (-i) and NAME (-n)"
return 1 return 1
fi fi
if [[ "$have_id" != "0" && ( "$id" != <-> || "$id" = "0" ) ]]; then if [[ "$have_id" != "0" && ( "$id" != <-> || "$id" = "0" ) ]]; then
pinfo "ID must be numeric, 1..100" __zconvey_pinfo "ID must be numeric, 1..100"
return 1 return 1
fi fi
@ -60,12 +60,12 @@ elif (( $have_id == 0 )); then
fi fi
if [[ "$id" != <-> || "$id" = "0" ]]; then if [[ "$id" != <-> || "$id" = "0" ]]; then
pinfo "Bad ID ($id), aborting" __zconvey_pinfo "Bad ID ($id), aborting"
return 1 return 1
fi fi
if [[ "$id" -gt "100" ]]; then if [[ "$id" -gt "100" ]]; then
pinfo "Maximum nr of sessions is 100, aborting" __zconvey_pinfo "Maximum nr of sessions is 100, aborting"
return 1 return 1
fi fi
@ -87,7 +87,7 @@ if [ -n "$other_id" ]; then
# it to the initial conflicting session $new_name # it to the initial conflicting session $new_name
print ":$subst_name:" > "$ZCONVEY_NAMES_DIR"/"$other_id".name print ":$subst_name:" > "$ZCONVEY_NAMES_DIR"/"$other_id".name
(( ${quiet} == 0 )) && pinfo "Pre-rename: $new_name -> $subst_name" (( ${quiet} == 0 )) && __zconvey_pinfo "Pre-rename: $new_name -> $subst_name"
break break
fi fi
@ -97,7 +97,7 @@ fi
print ":$new_name:" > "$ZCONVEY_NAMES_DIR"/"$id".name print ":$new_name:" > "$ZCONVEY_NAMES_DIR"/"$id".name
if (( ${quiet} == 0 )); then if (( ${quiet} == 0 )); then
pinfo2 "Renamed session $id to: $new_name" __zconvey_pinfo2 "Renamed session $id to: $new_name"
fi fi
local ls_after_rename local ls_after_rename