From 64eea6e774463e2ee305d44a0cc37256aab11510 Mon Sep 17 00:00:00 2001 From: Philippe Coval Date: Fri, 25 Oct 2019 17:34:38 +0200 Subject: [PATCH] Allow scripts to be run from outside user dir Change-Id: Ic8aba9e8372d31b6e11399f3500b66842f7a3f7d Signed-off-by: Philippe Coval --- f | 5 ++++- gl | 4 +++- rs | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/f b/f index 2da77e9..8078dbd 100755 --- a/f +++ b/f @@ -2,6 +2,9 @@ # ~/bin/f # Run ~/bin/w [find possibly misspelled words] on argument or current directory items (excluding hidden items) # This could be switched to include hidden items... +dir=$(dirname -- "$0") +dir=$(realpath -- "$dir" || { cd "$dir" && pwd ;}) + if [ -n "$1" ]; then where="$1" else @@ -43,4 +46,4 @@ Q="'" D1='$1' pDIR=`echo $DIR|perl -pne "s/(\\S+)/-name $D1 -prune -o /g"` pEXT=`echo $EXT|perl -pne "s/(\\S+)/-iname $Q*.$D1$Q -prune -o /g"` -find $where $pDIR $pEXT -type f -print0 | xargs -0 ~/bin/w | ~/bin/w 2>/dev/null +find $where $pDIR $pEXT -type f -print0 | xargs -0 "${dir}/w" | "${dir}/w" 2>/dev/null diff --git a/gl b/gl index 6b79949..43a0020 100755 --- a/gl +++ b/gl @@ -1,4 +1,6 @@ #!/bin/sh # ~/bin/gl # Run ~/bin/gl.pl -~/bin/gl.pl | uniq +dir=$(dirname -- "$0") +dir=$(realpath -- "$dir" || { cd "$dir" && pwd ;}) +"$dir/gl.pl" | uniq diff --git a/rs b/rs index 03bed02..d7f8cfa 100755 --- a/rs +++ b/rs @@ -4,6 +4,9 @@ # commit: s {spelling|new} # currently top level hidden directories are ignored, # this avoids accidentally scribbling over .hg/ or similar +dir=$(dirname -- "$0") +dir=$(realpath -- "$dir" || { cd "$dir" && pwd ;}) + old=$1 new=$2 if [ "$new" = "$HOME" ]; then @@ -31,6 +34,6 @@ esac find . -mindepth 1 -maxdepth 1 -type f -name '.*' -0 ) | xargs -0 grep $usenull -l -i "$old" | - xargs -0 -I '<>' ~/bin/r "s{$old}{$new}g" "<>" -~/bin/s "$word" + xargs -0 -I '<>' "${dir}/r" "s{$old}{$new}g" "<>" +"${dir}/s" "$word" #$(echo $new|tr A-Z a-z)