181 lines
3.6 KiB
Bash
181 lines
3.6 KiB
Bash
sync_git_remotes () {
|
|
for BRANCH in $(git remote); do
|
|
git pull $BRANCH master;
|
|
done
|
|
}
|
|
|
|
sync_git_repos () {
|
|
CURR=$(pwd);
|
|
for DIR in $(ls); do
|
|
cd $DIR; sync_git_remotes;
|
|
cd $CURR;
|
|
done
|
|
}
|
|
|
|
push_git_branches () {
|
|
REMOTE=${1:-origin}
|
|
git push $REMOTE
|
|
}
|
|
|
|
function git_current_branch() {
|
|
git branch | awk '/\*/ { print $2 }'
|
|
}
|
|
|
|
function is_git_branch_dirty {
|
|
[[ -z $(git status --porcelain) ]] || return 0
|
|
return 1
|
|
}
|
|
|
|
clean_vim_files() {
|
|
for F in $(find ./ -iname '*.swp'); do
|
|
echo "Deleting: ${F}";
|
|
rm -f $F;
|
|
done
|
|
}
|
|
|
|
big_files() {
|
|
SCRIPT="{if (\$7 > ${1}) print \$0;}"
|
|
find . -ls 2>/dev/null | awk "${SCRIPT}" | sort -n
|
|
}
|
|
|
|
get_clojure_libs() {
|
|
echo $(ls ~/Library/Clojure/*.jar | tr \\n \:)\
|
|
/Users/jwall/clojure_libs/src:/Users/jwall/clojure_libs/classes:.
|
|
}
|
|
|
|
get_jars() {
|
|
echo $(ls $1/*.jar | tr \\n \:)\
|
|
/Users/jwall/clojure_libs/src:/Users/jwall/clojure_libs/classes:.
|
|
|
|
}
|
|
|
|
function sync_music {
|
|
(cd ~/Music && rsync -r -v jwall@demachina:/media/OneTouch4/Music/* .)
|
|
(cd ~/Music && rsync -r -v . jwall@demachina:/media/OneTouch4/Music/*)
|
|
}
|
|
|
|
function str_replace_in_file {
|
|
text=$1
|
|
replacement=$2
|
|
file=$3
|
|
|
|
# TODO(jwall): handle failures
|
|
content=$(cat $file | sed "s/${text}/${replacement}/")
|
|
cat > $file << __CONTENT
|
|
$content
|
|
__CONTENT
|
|
}
|
|
|
|
function str_replace_in_files {
|
|
text=$1
|
|
replacement=$2
|
|
files=${@:3}
|
|
for f in $files; do
|
|
str_replace_in_file $text $replacement $f
|
|
done
|
|
}
|
|
|
|
function gen_password {
|
|
openssl rand 9 -base64
|
|
}
|
|
|
|
function mk_pass_entry {
|
|
cat << EOF
|
|
|
|
desc: $1
|
|
pass: $2
|
|
|
|
EOF
|
|
}
|
|
|
|
function update_pass_list {
|
|
read -p "description?> " desc
|
|
read -p "password?> " pass
|
|
echo "Decrypting password file"
|
|
gpg -d passwords.gpg > passwords
|
|
mk_pass_entry "$desc" "$pass" >> passwords
|
|
gpg -e -r 23EB9618 passwords
|
|
rm -f passwords
|
|
}
|
|
|
|
function get_cabal_depends() {
|
|
cat $1 | grep build-depends | sed 's/^ *//' | awk '{print $2}'
|
|
}
|
|
|
|
function insert_path_element() {
|
|
remove_element_from_var "$1" PATH
|
|
insert_element_into_var "$1" PATH
|
|
}
|
|
|
|
function insert_path_element_before() {
|
|
remove_element_from_var "$1" PATH
|
|
insert_element_at_front_of_var "$1" PATH
|
|
}
|
|
|
|
function remove_path_element() {
|
|
remove_element_from_var "$1" PATH
|
|
}
|
|
|
|
function insert_element_at_front_of_var () {
|
|
eval varcontents=\$"$2"
|
|
eval varname="$2"
|
|
newcomp="$1"
|
|
if echo "$varcontents" | grep "$newcomp:" >> /dev/null; then
|
|
true
|
|
elif [[ "$varcontents" == "" ]] ; then
|
|
export $varname="$newcomp"
|
|
else
|
|
export $varname="$newcomp:$varcontents"
|
|
fi
|
|
}
|
|
|
|
function insert_element_into_var () {
|
|
eval varcontents=\$"$2"
|
|
eval varname="$2"
|
|
newcomp="$1"
|
|
if echo "$varcontents" | grep "$newcomp:" >> /dev/null; then
|
|
true
|
|
elif [[ "$varcontents" == "" ]] ; then
|
|
export $varname="$newcomp"
|
|
else
|
|
export $varname="$varcontents:$newcomp"
|
|
fi
|
|
}
|
|
|
|
function remove_element_from_var() {
|
|
eval varcontents=\$"$2"
|
|
eval varname="$2"
|
|
newcomp="$1"
|
|
if echo "${varcontents}" | grep "${newcomp}:" >> /dev/null; then
|
|
newvarcontents="$(echo "${varcontents}" | sed "s%${newcomp}:%%")"
|
|
export $varname="${newvarcontents}"
|
|
elif [[ "$varcontents" == "$newcomp" ]] ; then
|
|
unset $varname
|
|
fi
|
|
}
|
|
|
|
function conditional_source() {
|
|
if [ -f $1 ]; then
|
|
source $1
|
|
fi
|
|
}
|
|
|
|
function start_emacs {
|
|
$(which emacs) --daemon
|
|
}
|
|
|
|
function rebase_hg_commit() {
|
|
target=$1
|
|
rev=$2
|
|
pname=temp_patch
|
|
hg qimport -n $pname -r $rev && \
|
|
hg qpop && \
|
|
hg checkout $target && \
|
|
hg qpush && \
|
|
hg qfinish $pname
|
|
}
|
|
|
|
function process_ip_lookup() {
|
|
until lsof -i@$1; do sleep 0.1; done
|
|
}
|