1
0
Fork 0
Scripts/paf.sh

29 lines
938 B
Bash
Raw Permalink Normal View History

2022-10-01 16:29:32 +02:00
#!/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.
2022-10-01 16:54:39 +02:00
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
2022-10-01 16:29:32 +02:00
script_dir="$HOME/.local/bin"
script="$(realpath "$1")"
2022-10-01 16:54:39 +02:00
[ ! -f "$script" ] && echo "$script does not exist." && exit 1
[ ! -x "$script" ] && echo "$script is not executable." && exit 1
if [[ -n "$2" ]]; then
2022-10-01 16:29:32 +02:00
script_name="$2"
else
script_name="$(basename "$script")"
script_name="${script_name%.*}" # remove extension
fi
2022-10-01 16:54:39 +02:00
2022-10-01 16:29:32 +02:00
ln -s "$script" "$script_dir/$script_name"