Skip to content

Commit

Permalink
Adding initial scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanoasis committed Oct 26, 2015
0 parents commit 6fd6c21
Show file tree
Hide file tree
Showing 37 changed files with 1,528 additions and 0 deletions.
5 changes: 5 additions & 0 deletions backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

echo "Back-up Files"

exit 0
12 changes: 12 additions & 0 deletions bash-aliases-abbreviated.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# aliases
alias g=git
alias gk='gitk &'
alias gka='gitk --all &'
alias gd='git diff'
alias gdc='git diff --cached'
if [[ "$OSTYPE" == 'linux-gnu' ]]; then
alias s=./symfony
alias symfony=./symfony
else
alias s=symfony
fi
29 changes: 29 additions & 0 deletions byzanz-record-region.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Delay before starting
DELAY=1

# Sound notification to let one know when recording is about to start (and ends)
beep() {
paplay /usr/share/sounds/KDE-Im-Irc-Event.ogg &
}

# Duration and output file
if [ $# -gt 0 ]; then
D="--duration=$@"
else
echo Default recording duration 10s to /tmp/recorded.gif
D="--duration=10 /tmp/recorded.gif"
fi

# xrectsel from https://github.com/lolilolicon/xrectsel
ARGUMENTS=$(xrectsel "--x=%x --y=%y --width=%w --height=%h") || exit -1

echo Delaying $DELAY seconds. After that, byzanz will start
for (( i=$DELAY; i>0; --i )) ; do
echo $i
sleep 1
done
#beep
byzanz-record --verbose --delay=0 ${ARGUMENTS} $D
#beep
42 changes: 42 additions & 0 deletions byzanz-screencapture-monitor1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
# @author Ryan McIntyre
# references:
# http://stackoverflow.com/questions/2642585/read-a-variable-in-bash-with-a-default-value

# default to 10
read -p "Duration of seconds to run (enter for default of 10): " DURATION
DURATION=${DURATION:-10}
echo $DURATION

# default to 0
read -p "X position (enter for default of 0): " XPOS
XPOS=${XPOS:-0}
echo $XPOS

# default to 0
read -p "Y position (enter for default of 0): " YPOS
YPOS=${YPOS:-0}
echo $YPOS

# default to 1920
read -p "Width (enter for default of 1920): " WIDTH
WIDTH=${WIDTH:-1920}
echo $WIDTH

# default to 1
read -p "Delay (enter for default of 1): " DELAY
DELAY=${DELAY:-1}
echo $DELAY

OUTDIR=~/Screencasts/byzanz
# e.g. 29-Apr-2014-07:31:31 PM
DATE=$(date +"%d-%b-%Y-%r")

# check if directory doesn't exist and not linked file
if [[ ! -d "${DESTINATION_DIR}" && ! -L "${DESTINATION_DIR}" ]] ; then
mkdir -p $OUTDIR
fi

byzanz-record --duration=$DURATION --x=$XPOS --y=$YPOS --width=$WIDTH --delay=$DELAY "$OUTDIR/screencast_$DATE.gif"

thunar $OUTDIR
42 changes: 42 additions & 0 deletions byzanz-screencapture-monitor2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
# @author Ryan McIntyre
# references:
# http://stackoverflow.com/questions/2642585/read-a-variable-in-bash-with-a-default-value

# default to 10
read -p "Duration of seconds to run (enter for default of 10): " DURATION
DURATION=${DURATION:-10}
echo $DURATION

# default to 1920
read -p "X position (enter for default of 1920): " XPOS
XPOS=${XPOS:-1920}
echo $XPOS

# default to 0
read -p "Y position (enter for default of 0): " YPOS
YPOS=${YPOS:-0}
echo $YPOS

# default to 1920
read -p "Width (enter for default of 1920): " WIDTH
WIDTH=${WIDTH:-1920}
echo $WIDTH

# default to 1
read -p "Delay (enter for default of 1): " DELAY
DELAY=${DELAY:-1}
echo $DELAY

OUTDIR=~/Screencasts/byzanz
# e.g. 29-Apr-2014-07:31:31 PM
DATE=$(date +"%d-%b-%Y-%r")

# check if directory doesn't exist and not linked file
if [[ ! -d "${DESTINATION_DIR}" && ! -L "${DESTINATION_DIR}" ]] ; then
mkdir -p $OUTDIR
fi

byzanz-record --duration=$DURATION --x=$XPOS --y=$YPOS --width=$WIDTH --delay=$DELAY "$OUTDIR/screencast_$DATE.gif"

thunar $OUTDIR
35 changes: 35 additions & 0 deletions byzanz-screencapture-via-xrectsel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# @author Ryan McIntyre
# references:
# http://stackoverflow.com/questions/2642585/read-a-variable-in-bash-with-a-default-value
# http://choorucode.com/2014/01/24/how-to-screen-capture-a-region-to-gif-using-byzanz/

# default to 10
read -p "Duration of seconds to run (enter for default of 10): " DURATION
DURATION=${DURATION:-10}
echo $DURATION

# default to 1
read -p "Delay (enter for default of 1): " DELAY
DELAY=${DELAY:-1}
echo $DELAY

OUTDIR=~/Screencasts/byzanz
# e.g. 29-Apr-2014-07:31:31 PM
DATE=$(date +"%d-%b-%Y-%r")

# check if directory doesn't exist and not linked file
if [[ ! -d "${DESTINATION_DIR}" && ! -L "${DESTINATION_DIR}" ]] ; then
mkdir -p $OUTDIR
fi

# xrectsel from https://github.com/lolilolicon/xrectsel
ARGUMENTS=$(xrectsel "--x=%x --y=%y --width=%w --height=%h") || exit -1

byzanz-record --verbose --delay=$DELAY ${ARGUMENTS} --duration=$DURATION "$OUTDIR/screencast_$DATE.gif"

thunar $OUTDIR




12 changes: 12 additions & 0 deletions custom-bash-prompt-git-railsdog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# original source:
# http://railsdog.com/blog/2009/03/07/custom-bash-prompt-for-git-branches/

function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}

function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}

export PS1='\W$(__git_ps1 "[\[\e[0;32m\]%s\[\e[0m\]\[\e[0;33m\]$(parse_git_dirty)\[\e[0m\]]")$ '
44 changes: 44 additions & 0 deletions dd-backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
# backup partitions using dd

echo "Back-up Files"

# variables
DATE=$(date +"%Y-%m-%d")
BACKUP_DIR_PARENT="/mnt/nas/msi-gp60-laptop"
DESTINATION_DIR=$BACKUP_DIR_PARENT/$DATE
# keep track of how long script takes to run
bench_start=$SECONDS
# store current path of script (help with relative paths)
MY_DIR=`dirname $0`

if [ -e $MY_DIR/unix-color-codes-not-escaped.sh ]; then
echo -e "${On_Green}Unix color code file found, including.. ${Color_Off}"
$MY_DIR/unix-color-codes-not-escaped.sh
else
echo -e "${On_Red}Unix color code file not found${Color_Off}"
fi

# check if directory doesn't exist and not linked file
if [[ ! -d "${DESTINATION_DIR}" && ! -L "${DESTINATION_DIR}" ]] ; then
echo -e "${On_Blue}Directory not found, probably first time running. creating: $DESTINATION_DIR${Color_Off}"
# Control will enter here if $DIR doesn't exist.
mkdir -p $DESTINATION_DIR
# compare exit stats/code of last cmd
if [ "$?" -ne "0" ]; then
echo -e "${On_Red}Sorry, could not create the directory: ${DESTINATION_DIR} ${Color_Off}"
exit 1
fi
fi

# home backup
sudo dd if=/dev/sda7 | gzip -9 > $DESTINATION_DIR/sda7_home.img.gz
# filesystem root
sudo dd if=/dev/sda8 | gzip -9 > $DESTINATION_DIR/sda8_filesystem.img.gz

bench_end=$SECONDS

total_time=$(expr $bench_end - $bench_start)

echo "Backup finished successfully [total time in seconds: $total_time]"
#exit 0
5 changes: 5 additions & 0 deletions dropbox-thunar-hack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
exec thunar ~/Dropbox
exit 0
# sources:
# http://unix.stackexchange.com/questions/34045/how-can-i-change-which-file-manager-dropbox-opens-with-by-default
15 changes: 15 additions & 0 deletions find-class-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
# @author Ryan McIntyre

# e.g. 1
cat lib/model/doctrine/base/*.class.php | sed 's|\r$||' | sort | uniq --all-repeated | uniq --count | grep "class " | grep -v '*'

# e.g. 2
cat lib/model/doctrine/*.class.php | sed 's|\r$||' | sort | uniq --all-repeated | uniq --count | grep "class " | grep -v '*'

# e.g. 3
cat lib/form/doctrine/base/*.class.php | sed 's|\r$||' | sort | uniq --all-repeated | uniq --count | grep "class " | grep -v '*'


# e.g. latest
cat lib/form/doctrine/*.class.php | sed 's|\r$||' | sort | uniq --all-repeated | uniq --count | grep "class " | grep -v '*'
4 changes: 4 additions & 0 deletions find-duplicate-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
#

find -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate
6 changes: 6 additions & 0 deletions find-files-not-owned-by-user-group.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
# Find/list files not owned by user and group given
USER=ryan
GROUP=ryan

sudo find . ! -user $USER -o ! -group $GROUP | more
29 changes: 29 additions & 0 deletions git-bash-ps1-examples.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

# source
# https://makandracards.com/makandra/1090-customize-your-bash-prompt

export PS1='\h \w$(__git_ps1 "(%s)") \$ '
=> mycomputer ~/apps/chess/tmp(master) $ _

export PS1='\[\e[33m\]\h\[\e[0m\]:\W\[\e[33m\]$(__git_ps1 "(%s)")\[\e[0m\] \u\$ '
=> mycomputer:tmp(master) tom$ _

# Henning's awesome TRON prompt 2.0.2 with current Git branch and success state of the last command (the syntax coloring here does not do it justice):
export PS1='`if [ $? = 0 ]; then echo "\[\033[01;32m\]✔"; else echo "\[\033[01;31m\]✘"; fi` \[\033[01;30m\]\h\[\033[01;34m\] \w\[\033[35m\]$(__git_ps1 " %s") \[\033[01;30m\]>\[\033[00m\] '
=> ✔ mycomputer ~/projects/platforms master > _

# Arne's epic timestamped prompt with return status indicator and status-colored (green or red, if unstaged) git branch:
export PS1='\[\e[01;30m\]\t `if [ $? = 0 ]; then echo "\[\e[32m\]"; else echo "\[\e[31m\]✘"; fi` \[\e[00;37m\]\u\[\e[01;37m\]:`[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "\[\e[31m\]" || echo "\[\e[32m\]"`$(__git_ps1 "(%s)\[\e[00m\]")\[\e[01;34m\]\w\[\e[00m\]\$ '
=> 03:13:37 ✔ arne:(master)~/projects/geordi$ _

# Arne's danger prompt for root use. No git information and alarming red and yellow (which you can't see here):
export PS1='\[\e[01;30m\]\t \[\e[31m\]\u\[\e[37m\]:\[\e[33m\]\w\[\e[31m\]\$\[\033[00m\] '
=> 03:13:37 root:/tmp/foo# _

# Kim's mix of those above with small changes. TRON promt with timestamp, return status indicator, hostname, git informations and working directory (but all non-bold).
export PS1='\[\033[01;30m\]\t `if [ $? = 0 ]; then echo "\[\033[01;32m\]ツ"; else echo "\[\033[01;31m\]✗"; fi` \[\033[00;32m\]\h\[\033[00;37m\]:\[\033[31m\]$(__git_ps1 "(%s)\[\033[01m\]")\[\033[00;34m\]\w\[\033[00m\] >'
=> 03:13:37 ツ mycomputer:(master)~/code/foo >

# Kim's root promt (the same as above without git and the hostname is red)
export PS1='\[\033[01;30m\]\t `if [ $? = 0 ]; then echo "\[\033[01;32m\]ツ"; else echo "\[\033[01;31m\]✗"; fi` \[\033[00;31m\]\h\[\033[00;37m\]:\[\033[00;34m\]\w\[\033[00m\] >'
=> 03:13:37 ツ mycomputer:~/code/foo >
8 changes: 8 additions & 0 deletions git-diff-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

# diff is called by git with 7 parameters:
# path old-file old-hex old-mode new-file new-hex new-mode
"C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe" "$2" "$5" | cat

#"C:/Program Files/WinMerge/WinMergeU.exe" "$2" "$5" | cat
#"C:/Program Files/KDiff3/kdiff3.exe" "$2" "$5" | cat
20 changes: 20 additions & 0 deletions git-hook-console-log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

# git diff --cached = stagged changes
# git diff = all changes

has_console_log=$(git diff --cached | grep -F 'console.log')

if [ "$has_console_log" != "" ]
then
echo "ERROR: You have console.log in your changes. Consider removing them."
exit 1
fi

has_console_log=$(git diff | grep -F 'console.log')

if [ "$has_console_log" != "" ]
then
echo "ERROR: You have console.log in your changes. Consider removing them."
exit 1
fi
20 changes: 20 additions & 0 deletions git-hook-trailing-whitespace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh
# source: http://css.dzone.com/articles/all-git-hooks-you-need
# Force remove trailing-whitespaces (and carriage-return in linux)

if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

# Find files with trailing whitespace
for FILE in `exec git diff-index --check --cached $against -- | sed '/^[+-]/d' | cut -f1 -d: | uniq` ; do
# Fix them!
sed -i 's/\s\+$//' "$FILE"
git add "$FILE"
done

exit
9 changes: 9 additions & 0 deletions git-merge-diffmerge-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

# Passing the following parameters to mergetool:
# local base remote merge_result

# params should come as: "$PWD/$LOCAL" "$PWD/$BASE" "$PWD/$REMOTE" "$PWD/$MERGED"
#"C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe" "$1" "$2" "$3" --result="$4" --title1="Mine" --title2="Merging to: $4" --title3="Theirs"
#"C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe" "$1" "$2" "$3" --result="$4" --title1="Mine (LOCAL - Current branch verion (probably master?))" --title2="Merging to: $4" --title3="Theirs (REMOTE - Version to be merged (probably a topic branch?))"
diffmerge "$1" "$2" "$3" --result="$4" --title1="Mine (LOCAL - Current branch verion (probably master?))" --title2="Merging to: $4" --title3="Theirs (REMOTE - Version to be merged (probably a topic branch?))"
Loading

0 comments on commit 6fd6c21

Please sign in to comment.