From d9daae4cc496a501a6c8abd8e6cef92b0a0ef4cf Mon Sep 17 00:00:00 2001 From: dece Date: Sat, 1 Oct 2022 16:54:39 +0200 Subject: [PATCH] fix install again, again --- install-scripts.sh | 9 ++++++--- paf.sh | 14 +++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/install-scripts.sh b/install-scripts.sh index f94c883..6d0430b 100755 --- a/install-scripts.sh +++ b/install-scripts.sh @@ -2,8 +2,11 @@ # Install scripts from this repo using our neighbour paf.sh. # Requires fdfind and fzf to work. -script_dir="$( cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )" -paf="$script_dir/paf.sh" +our_dir="$( cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )" +paf="$our_dir/paf.sh" +scripts_dir="$1" +[[ -z "$scripts_dir" ]] && scripts_dir="$our_dir" -fdfind -t x | fzf --multi --layout=reverse --header="Pick scripts to install" \ +fdfind -t x . "$scripts_dir" \ + | fzf --multi --layout=reverse --header="Pick scripts to install" \ | while read -r script; do "$paf" "$script"; done diff --git a/paf.sh b/paf.sh index 372f013..57c54c4 100755 --- a/paf.sh +++ b/paf.sh @@ -5,12 +5,24 @@ # exists at the link path, the script fails (last command is ln itself). This is # intentional. +usage() { + echo "Usage: $0 script [link_name]" + echo " script script or executable to install" + echo " link_name name to use for the symbolic link" +} + +[ $# -lt 1 ] || [ $# -gt 2 ] && usage && exit 1 + script_dir="$HOME/.local/bin" script="$(realpath "$1")" -if [ -n "$2" ]; then +[ ! -f "$script" ] && echo "$script does not exist." && exit 1 +[ ! -x "$script" ] && echo "$script is not executable." && exit 1 + +if [[ -n "$2" ]]; then script_name="$2" else script_name="$(basename "$script")" script_name="${script_name%.*}" # remove extension fi + ln -s "$script" "$script_dir/$script_name"