Skip to content

Instantly share code, notes, and snippets.

@derixithy
Last active October 22, 2015 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derixithy/86f4d715e9cf3341e9d1 to your computer and use it in GitHub Desktop.
Save derixithy/86f4d715e9cf3341e9d1 to your computer and use it in GitHub Desktop.
Bash
#!/bin/bash
# Do not remove permanently
function rm {
mv $1 ~/.Trash # Probably needs a check if dir exists
}
# grep bash history
function grash() {
grep --color $1 ~/.bash_history
}
BIN_DEPS="id $READLINK ls basename ls pwd cut"
#Dependencies check
for i in $BIN_DEPS; do
which $i > /dev/null
if [ $? -ne 0 ]; then
echo -e "Error: Required program could not be found: $i"
exit 1
fi
done
pause() {
local dummy
read -s -r -p "Press any key to continue..." -n 1 dummy
}
#!/bin/bash
# List permissions in folder
ls -l
# List permissions of folder
ls -ld
# Copy permissions from file to file
function transferRights() {
USAGE="$0 <source> <destination>"
if [ "$#" -ne 2 ]; then
echo "$USAGE"
else
chmod --reference=$1 $2
fi
}
function chmodFiles() {
USAGE="$0 <source> <permissions>"
if [ "$#" -ne 2 ]; then
echo "$USAGE"
else
find $1 -type f -iname "*" -print0 | xargs -I {} -0 chmod $2 {}
fi
}
function chmodFolders() {
USAGE="$0 <source> <permissions>"
if [ "$#" -ne 2 ]; then
echo "$USAGE"
else
find $1 -type d -iname "*" -print0 | xargs -I {} -0 chmod $2 {}
fi
}
#To be continued.....
#!/bin/bash
function pomodoro {
local worktime="${1:-25m}" pausetime="${2:-3m}" beepcount="${3:-3}"
local breakmsg="${4:-'Yout need to take a break!'}"
local startmsg="${5:-'Get set, ready? Go!!'}"
case "$1" in
'stop|quit')
rm /tmp/pomodoro.bash.lock
;;
'help|-h|--help')
echo "usage: $0 <worktime:$worktime> <pausetime:$pausetime>"
;;
*)
touch /tmp/pomodoro.bash.lock && trap 'rm /tmp/pomodoro.bash.lock && exit' EXIT
while [[ -f /tmp/pomodoro.bash.lock ]]
do
notify-send "$startmsg"
sleep $worktime
if [[ -f /tmp/pomodoro.bash.lock ]]
then # still running
notify-send "$breakmsg"
for count in $beepcount
do
echo -en "\007"
sleep 1s
done
sleep $pausetime
fi
done
;;
esac
}
pomodoro $@
#!/bin/bash
alias reload='source ~/.bash_profile'
function edit_bash() {
vim ~/.bash_profile
reload
}
#!/bin/bash
# Run script in bash without saving
wget -qO - "$1" | bash
# Print routing table
netstat -nr inet
# Get Ubuntu release name
lsb_release -sc
# Exit script on error
set -e
# Bash version
bash --version
# Shellshock test
env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
# Colorfull text wrapper - Handy in scripts
printf '\033]2;%s\033\\' "$1"
# Track dependancies
ldd $1
# Generate passwords
apg -a 0 -t -s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment