From 786cf8cd9cd177cefb93609675b66a125fc42db9 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Thu, 10 Sep 2026 14:03:11 +0100 Subject: [PATCH] xbmk: allow to run from PATH now you can put lbmk somewhere on your system, and symlink to the mk script from PATH e.g. /usr/local/bin/lbmk -> /home/leah/lbmk/mk lbmk will cd to itself, including from PATH, because the string will then be passed through readlink, which gets the real path. Signed-off-by: Leah Rowe --- mk | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/mk b/mk index 40ecfffb..aa7c016c 100755 --- a/mk +++ b/mk @@ -10,29 +10,21 @@ set -u -e xrval=0 ( -ispwd="true" xbdir="" +xbarg0="$0" -if [ "$0" != "./mk" ]; then - if [ "${0##*/}" != "$0" ]; then - xbdir="`readlink -f "$0" 2>/dev/null`" - if [ -z "$xbdir" ]; then - xbdir="`realpath "$0" 2>/dev/null`" - fi - cd "${xbdir%/*}" || exit 1 - else - ispwd="false" - fi +if [ "${0##*/}" = "$0" ]; then + xbarg0="`command -v "$0"`" + xbdir="${xbarg0%/*}" + xbcddir="$xbdir" fi -if [ "$ispwd" = "true" ] && [ -L "mk" ]; then - ispwd="false" +xbcddir="`readlink -f "$0" 2>/dev/null`" +if [ -z "$xbcddir" ]; then + xbcddir="`realpath "$0" 2>/dev/null`" fi -if [ "$ispwd" = "false" ]; then - printf "You must run this in the proper work directory.\n" 1>&2 - exit 1 -fi +cd "${xbcddir%/*}" || exit 1 . "include/lib.sh" . "include/init.sh"