aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Harder <radhermit@gmail.com>2016-02-27 11:41:24 -0500
committerTim Harder <radhermit@gmail.com>2016-02-27 11:45:44 -0500
commit6b3975b5cc2bea5c1c95b25aa7817bc90cc089e4 (patch)
tree6aa3136e67f551374ecf86c81cbf2089ec43f700
parentshell/bin/psite: exit if _pkgattr() returns an error (diff)
downloadpkgcore-6b3975b5cc2bea5c1c95b25aa7817bc90cc089e4.tar.gz
pkgcore-6b3975b5cc2bea5c1c95b25aa7817bc90cc089e4.tar.bz2
pkgcore-6b3975b5cc2bea5c1c95b25aa7817bc90cc089e4.zip
shell: extract caller info into its own method
-rw-r--r--shell/bash/pkgcore.bash18
-rw-r--r--shell/zsh/pkgcore.zsh7
2 files changed, 18 insertions, 7 deletions
diff --git a/shell/bash/pkgcore.bash b/shell/bash/pkgcore.bash
index b4f81af2e..0afaea703 100644
--- a/shell/bash/pkgcore.bash
+++ b/shell/bash/pkgcore.bash
@@ -3,12 +3,7 @@
# get an attribute for a given package
_pkgattr() {
- local prog
- if [[ ${FUNCNAME[-1]} == "source" ]]; then
- prog=$(basename ${BASH_SOURCE[-1]})
- else
- prog=${FUNCNAME[-1]}
- fi
+ local prog=$(_get_caller)
local pkg_attr=$1 pkg_atom=$2 repo=$3
local ret=0 pid fdout fderr
local -a pkg error
@@ -59,6 +54,17 @@ _pkgattr() {
echo ${pkg[${choice}]#*:}
}
+# get the caller of the current function
+_get_caller() {
+ local caller
+ if [[ ${FUNCNAME[-1]} == "source" ]]; then
+ caller=$(basename ${BASH_SOURCE[-1]})
+ else
+ caller=${FUNCNAME[-1]}
+ fi
+ echo ${caller}
+}
+
# cross-shell compatible PATH searching
_which() {
type -P "$1" >/dev/null
diff --git a/shell/zsh/pkgcore.zsh b/shell/zsh/pkgcore.zsh
index 73ec1efea..6a3a2b972 100644
--- a/shell/zsh/pkgcore.zsh
+++ b/shell/zsh/pkgcore.zsh
@@ -3,7 +3,7 @@
# get an attribute for a given package
_pkgattr() {
- local prog=${${funcstack[-1]}:t}
+ local prog=$(_get_caller)
local pkg_attr=$1 pkg_atom=$2 repo=$3
local ret=0 pid fdout fderr
local -a pkg error
@@ -54,6 +54,11 @@ _pkgattr() {
echo ${pkg[${choice}]#*:}
}
+# get the caller of the current function
+_get_caller() {
+ echo ${${funcstack[-1]}:t}
+}
+
# cross-shell compatible PATH searching
_which() {
whence -p "$1" >/dev/null