From f02910e9aa5c3c36e7a4794278ac7924d2d59bee Mon Sep 17 00:00:00 2001 From: dece Date: Sat, 1 Oct 2022 16:29:32 +0200 Subject: [PATCH] change install system --- install-scripts.sh | 9 +++++++++ install.sh | 16 ---------------- paf.sh | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 16 deletions(-) create mode 100755 install-scripts.sh delete mode 100755 install.sh create mode 100755 paf.sh diff --git a/install-scripts.sh b/install-scripts.sh new file mode 100755 index 0000000..f94c883 --- /dev/null +++ b/install-scripts.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# 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" + +fdfind -t x | fzf --multi --layout=reverse --header="Pick scripts to install" \ + | while read -r script; do "$paf" "$script"; done diff --git a/install.sh b/install.sh deleted file mode 100755 index 894cf4b..0000000 --- a/install.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -ensure_has() { - if ! command -v "$1" > /dev/null; then - echo "Can't find $1." - exit 1 - fi -} - -ensure_has fdfind -ensure_has fzf -ensure_has install-script - -fdfind -t x \ - | fzf -m --layout=reverse \ - | while read -r script; do install-script "$script"; done diff --git a/paf.sh b/paf.sh new file mode 100755 index 0000000..372f013 --- /dev/null +++ b/paf.sh @@ -0,0 +1,16 @@ +#!/bin/bash -e +# A script to install other scripts! Create a symbolic link to the path passed +# as first argument in ~/.local/bin and strip the extension. If a second +# argument is passed, this name is used (unstripped) instead. If a file already +# exists at the link path, the script fails (last command is ln itself). This is +# intentional. + +script_dir="$HOME/.local/bin" +script="$(realpath "$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"