mirror of
https://github.com/bytedream/scripts.git
synced 2025-05-09 12:15:12 +02:00
Added pathify
This commit is contained in:
parent
dadf7c31fa
commit
fcc0270ac3
18
pathify/README.md
Normal file
18
pathify/README.md
Normal 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
44
pathify/pathify.sh
Executable 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
|
Loading…
x
Reference in New Issue
Block a user