Skip to content

Commit

Permalink
Added new functions.
Browse files Browse the repository at this point in the history
Adding gitigonre fire.
  • Loading branch information
benzamin committed May 16, 2016
1 parent 960d76c commit c88e042
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
73 changes: 48 additions & 25 deletions mamu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ fileExists(){
readInputFile()
{
until [ "$FILE_PATH" ]; do
read -e -p "${COLOR_BLUE}$1 ${COLOR_NONE}" FILE_PATH
read -e -p "${COLOR_BLUE}$1 ${COLOR_NONE}" FILE_PATH
done
echo $(abspath "$FILE_PATH")
}

readText()
{
until [ "$INPUT_TEXT" ]; do
read -p "${COLOR_BLUE} $1 ${COLOR_NONE}" INPUT_TEXT
read -p "${COLOR_BLUE} $1 ${COLOR_NONE}" INPUT_TEXT
done
echo $INPUT_TEXT
}
Expand All @@ -75,6 +75,7 @@ rtrim() #{{{1 # Removes all trailing whitespace (from the right).
}
trim() #{{{1 # Removes all leading/trailing whitespace
{
#could've been very simple, like TRIMMED_PATH=`echo "$SOME_PATH" | sed 's/^ *//;s/ *$//'`
ltrim "$1" | rtrim "$1"
}
squeeze() #{{{1 # Removes leading/trailing whitespace and condenses all other consecutive whitespace into a single space.
Expand Down Expand Up @@ -129,8 +130,8 @@ countdown() {
SECONDS=0
if [ $# -lt 1 ]
then
echo ":::TIPS::: You can also use countdown command like - $ mamu countdown 10 "
read -p "How many seconds you want to countdown? -> " SECONDS
printTipsText "You can also use countdown command like - $ mamu countdown 10 "
SECONDS=$(readText "How many seconds you want to countdown? -> ")
else
SECONDS=$1
fi
Expand All @@ -152,20 +153,18 @@ findnreplace(){

if [ $# -lt 3 ]
then
IFS="
"
echo ":::TIPS::: You can also use findnreplace command like - $ mamu findnreplace /Desktop/myFile.txt 'Old text' 'New text' "
read -e -p "In which file you want to find a replace text? -> " FILE_NAME
read -p "Which text you want to find? -> " FIND_TEXT
read -p "What text you want to replace with? -> " REPLACE_TEXT
printTipsText "You can also use findnreplace command like - $ mamu findnreplace /Desktop/myFile.txt 'Old text' 'New text'"
FILE_NAME=$(readInputFile "In which file you want to find a replace text? -> ")
FIND_TEXT=$(readText "Which text you want to find? -> ")
REPLACE_TEXT=$(readText "What text you want to replace with? -> ")
else
FILE_NAME=$1
FIND_TEXT=$2
REPLACE_TEXT=$3
fi
##remove the white spaces
FILE_NAME=`echo "$FILE_NAME" | sed 's/^ *//;s/ *$//'`

sed -i.bak "s/$FIND_TEXT/$REPLACE_TEXT/g" $FILE_NAME

DIRECTORY_NAME=$(dirname "$FILE_NAME")
Expand All @@ -176,25 +175,22 @@ findtext()
{
SEARCH_TEXT=""
SEARCH_PATH=""

if [ $# -lt 2 ]
then
IFS="
"
printTipsText "You can also use findtext command like - $ mamu findtext 'love' ~/Desktop/Song-Lyrics"
read -p "${COLOR_GREEN}What text you want to search in files? -> " SEARCH_TEXT
read -e -p "Which folder/path you want to search? ${COLOR_NONE}->" SEARCH_PATH
SEARCH_PATH=$(readInputFile "Which folder/path you want to search? ${COLOR_NONE}->")
SEARCH_TEXT=$(readText "${COLOR_GREEN}What text you want to search in files? -> " )
else
SEARCH_TEXT="$1"
SEARCH_PATH="$2"
SEARCH_PATH=$(abspath "$1")
SEARCH_TEXT="$2"

fi

SEARCH_PATH=`echo "$SEARCH_PATH" | sed 's/^ *//;s/ *$//'`

grep -irw -n $SEARCH_PATH -e "$SEARCH_TEXT"
#grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"
#grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern"
}
}

symboliclink()
{
Expand All @@ -203,7 +199,7 @@ symboliclink()
DESTINATION_PATH=""
if [ $# -lt 2 ]
then
printTipsText "You can also use symboliclink command like - $ mamu symboliclink /Users/benzamin/Desktop/Songs/MichelJackson /Users/benzamin/Desktop/"
printTipsText "You can also use symboliclink command like - $ mamu symboliclink ~/Desktop/Songs/MichelJackson ~/Desktop/FavouriteSongs"
SOURCE_PATH=$(readInputFile "Which folder/file you want to make symbolic-link of? -> " )
DESTINATION_PATH=$(readInputFile "Where to put the symbolic-link? -> ")
else
Expand All @@ -216,8 +212,37 @@ symboliclink()
if [ $? -eq 0 ]; then
printSuccessText "Made a symbolic link from $SOURCE_PATH to $DESTINATION_PATH"
fi
}
}

httpserver()
{
if [ $# -ne 1 ]; then
printTipsText "You can also use findnreplace command like - $ mamu simpleserver 8080"
python -m SimpleHTTPServer 8080
else
python -m SimpleHTTPServer $1
fi

}

killnode(){

if [ $# -ne 1 ]; then
printTipsText "You can also use findnreplace command like - $ mamu killnode app.js"
kill $(ps aux | grep .js | awk '{print $2}')
if [ $? -eq 0 ]; then
printSuccessText "Killed all node process!"
fi
else
PROCESS_NAME="$1"
kill $(ps aux | grep $PROCESS_NAME | awk '{print $2}')
if [ $? -eq 0 ]; then
printSuccessText "Killed $PROCESS_NAME node process!"
fi
fi


}


########################################
Expand All @@ -232,5 +257,3 @@ fi
exit




0 comments on commit c88e042

Please sign in to comment.