-
-
Save blackwatertepes/947495 to your computer and use it in GitHub Desktop.
Shell script for creating/destroying/opening .pow symlinks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Scripts for creating/deleting/viewing pow symlinks | |
# Created by Tyler J. (first ever bash!!!) | |
a=`pwd` | |
b=`basename -a $a` | |
create() | |
{ | |
# Create a pow symlink | |
if [ ! -d ~/.pow/$b/ ] | |
then | |
ln -s $a ~/.pow/$b | |
echo 'Pow symlink created' | |
else | |
echo 'Pow symlink already exists' | |
fi | |
c=`echo $b'.dev'` | |
echo $c | |
} | |
delete() | |
{ | |
#Delete pow symlink | |
if [ -d ~/.pow/$b/ ] | |
then | |
rm -rf ~/.pow/$b | |
echo 'Pow symlink deleted' | |
else | |
echo 'Pow symlink does not exist' | |
fi | |
} | |
list() | |
{ | |
# Listing pow symlinks | |
ls ~/.pow/ | |
} | |
openpow() | |
{ | |
#Opens the project in pow via the users default browswer | |
#If no symlink exists, then one is created | |
if [ -d ~/.pow/$b/ ] | |
then | |
echo 'Opening pow @'$b'.dev...' | |
open 'http://'$b'.dev' | |
else | |
create | |
openpow | |
fi | |
} | |
powhelp() | |
{ | |
echo 'Pow Commands:' | |
echo 'create (c)' | |
echo 'delete (d, del)' | |
echo 'list (l, li)' | |
echo 'open (o)' | |
echo 'help (?, h)' | |
} | |
find_command() | |
{ | |
#Matches the command argument against the command shortcuts | |
com=$1 | |
if [ $1 == 'c' ] | |
then | |
com='create' | |
fi | |
if [ $1 == 'd' ] || [ $1 == 'del' ] | |
then | |
com='delete' | |
fi | |
if [ $1 == 'l' ] || [ $1 == 'li' ] | |
then | |
com='list' | |
fi | |
if [ $1 == 'o' ] | |
then | |
com='open' | |
fi | |
if [ $1 == 'h' ] || [ $1 == '?' ] | |
then | |
com='help' | |
fi | |
} | |
#Execute | |
if [ $1 ] | |
then | |
find_command $1 | |
if [ $com == 'create' ] | |
then | |
create $2 | |
fi | |
if [ $com == 'delete' ] | |
then | |
delete | |
fi | |
if [ $com == 'list' ] | |
then | |
list | |
fi | |
if [ $com == 'open' ] | |
then | |
openpow | |
fi | |
if [ $com == 'help' ] | |
then | |
if [ $2 ] | |
then | |
find_command $2 | |
echo 'Usage for command: '$com | |
case "$com" in | |
'create') echo "Creates a pow symlink in the .pow directory using the current directory name";; | |
'delete') echo "Deletes the pow symlink";; | |
'list') echo "Lists all pow symlinks in the .pow directory";; | |
'open') echo "Opens the current directory in pow via users default web browser" | |
echo "If no pow symlink exists, then one is automatically created";; | |
'help') echo "Why are you hasseling me?";; | |
*) echo "No such command: '"$2"'" | |
echo "Type 'pow help' for available commands" ;; | |
esac | |
else | |
powhelp | |
fi | |
fi | |
else | |
create | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create file 'pow', and place in /usr/bin/
Then type 'pow help' for a command list.