Added pathify

This commit is contained in:
ByteDream 2021-05-20 13:18:55 +02:00
parent dadf7c31fa
commit fcc0270ac3
2 changed files with 62 additions and 0 deletions

18
pathify/README.md Normal file
View File

@ -0,0 +1,18 @@
## Pathify
A script to make other bash scripts in this repository global available on your computer
#### Usage
Make a script global
```
$ ./pathify.sh <script name>
```
Remove a script
```
$ ./pathify.sh -f <script name>
```
NOTE: The `script name` can only be the name of a folder in the repository root

44
pathify/pathify.sh Executable file
View File

@ -0,0 +1,44 @@
#!/bin/bash
while getopts "?l?f?" opt; do
case $opt in
l)
link=true
;;
f)
force=true
;;
esac
done
shift $((OPTIND -1))
if [ $# -ge 1 ]; then
path="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)/../$1"
if [ -d $path ]; then
executablePath="/usr/bin/$1"
copyDir="/usr/share/$1"
if [ -f $executablePath ] || [ -d $copyDir ]; then
if [ ! -z $force ]; then
rm $executablePath
if [ -d $copyDir ]; then
rm -r $copyDir
fi
echo "Unpathified $1"
else
echo "The script is already installed"
fi
elif [ ! -z $link ]; then
ln -s "$path/$1.sh" $executablePath
echo "Pathified $1"
else
cp -r $path /usr/share
ln -s "/usr/share/$1/$1.sh" $executablePath
echo "Pathified $1"
fi
else
echo "This script does not exist"
fi
else
echo "No script to pathify were given"
fi