Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

311 lines (297 sloc) 6.202 kB
#!/usr/bin/env bash
less()
{
typeset param parsed
typeset -a params
if (( $# == 1 )) && [[ -f "$1" ]] && (( $(wc -l < "$1") < ${LINES:-20} ))
then
cat $1
return 0
fi
for param in "$@"
do
case $param in
(*:*)
if [[ -f "$param" ]]
then
params+=( "$param" )
else
parsed=( ${param//:/ } )
params+=( "-N" "+j${parsed[1]}" "${parsed[0]}" )
fi
;;
(*)
params+=( "$param" )
;;
esac
done
command less "${params[@]}"
}
get()
{
typeset count url file
count=$1
url=$2
file=$3
if [[ -z "$count" ]]
then
echo "Usage: $0 [count] url [target]"
return 1
fi
if [[ -z "$url" ]]
then
url="$count"
count=2
fi
if [[ -z "$file" ]]
then
file="$(basename "${url%%\?*}")";
fi
echo "Save $url to $file in $count threads."
aria2c -c -x $count -j $count -s $count $url -o $file
}
if ! which wget > /dev/null 2>&1
then
wget()
{
curl $1 -o $(basename $1)
}
fi
if ! which ldd > /dev/null 2>&1 && which otool > /dev/null 2>&1
then
ldd()
{
otool -L "$@"
}
fi
d()
{
[[ -d $1 ]] || mkdir -p $1
cd $1
}
gwmpush()
{
git pull $@ && git pull bitbucket master $@ && git push && git push bitbucket master
}
gpp()
{
git pull $@ && git push
}
gcaa()
{
git add .
git commit --amend
}
gcamp()
{
gcam "$@"
gpp
}
gcam()
{
git add .
git commit -m "$*"
}
gcm()
{
git commit -m "$*"
}
gf()
{
typeset command subcommand version
command=$1
subcommand=$2
version=${3:-}
case $command in
(r*) command=release ;;
(h*) command=hotfix ;;
esac
case $subcommand in
(s*) subcommand=start ;;
(f*) subcommand=finish ;;
esac
if [[ -z "$version" ]]
then
case "$command-$subcommand" in
(release-start) version=$(awk -F "[.-]" '{ if ($4=="") print $1"."$2+1".0"; else print $1"."$2"."$3;}' < VERSION ) ;; #'
(hotfix-start) version=$(awk -F "." '{ print $1"."$2"."$3+1}' < VERSION ) ;;
(*-finish) version=$(cat VERSION) ;;
esac
fi
git flow $command $subcommand $version
if [[ "$subcommand" == "start" ]]
then
echo $version > VERSION
git add VERSION
git commit -m $version
fi
}
show_git() {
typeset limit path top
limit=$(git config dir.limit 2>/dev/null)
path="$PWD"
top=$(git rev-parse --show-toplevel 2>/dev/null)
[[ -z "$limit" ]] && return 0
while (( limit >= 0 ))
do
case "$path" in
($top) return 0 ;;
(/|$HOME) return 1 ;;
esac
path="$( dirname "$path" )"
: $(( --limit ))
done
return 1
}
function pgd {
show_git && git status --porcelain 2>/dev/null |
sed 's/^\(.\)\(.\).*$/\1 \2/' | # ?? ... => ? ?
awk -v out="$1" '
BEGIN { x=0;y=0; }
$1!=" " && $1!="?"{ x++; }
$2!=" "{ y++; }
END{
if(out==""){
if(x>0)print "uncomitted"; else if (y>0) print "dirty";
}
else{
if(x>0||y>0)print out;
}
}
'
}
function pgb {
show_git && __git_ps1 "${1:-%s}" 2>/dev/null
}
function pgr {
show_git && git status 2>/dev/null | awk -v out="$1" '/# Your branch is / { if(out=="") printf $5; else printf out }' #'
}
function _rvm_curr {
typeset __rvm_curr
__rvm_curr=$(__rvm_env_string)
[[ -n "${__rvm_curr}" ]] && printf "${__rvm_curr##ruby-} "
}
function show_function() {
typeset -f $@
}
function edit_function() {
typeset body name
name="$*"
name="${name// /-}"
if
(( $# > 0 )) &&
show_function $@ >/dev/null
then
show_function $@ > ${TMPDIR:-/tmp}/__function_${name}_1.sh
cp -f ${TMPDIR:-/tmp}/__function_${name}_1.sh ${TMPDIR:-/tmp}/__function_${name}_2.sh
${EDITOR:-vim} ${TMPDIR:-/tmp}/__function_${name}_1.sh
diff -qwB ${TMPDIR:-/tmp}/__function_${name}_1.sh ${TMPDIR:-/tmp}/__function_${name}_2.sh >/dev/null ||
source ${TMPDIR:-/tmp}/__function_${name}_1.sh
rm -f ${TMPDIR:-/tmp}/__function_${name}_{1,2}.sh
else
echo "there is no function $name"
fi
}
function edit_variable() {
typeset body name
name="$*"
name="${name// /-}"
if
(( $# > 0 )) &&
eval "[[ -n \${$1} ]]"
then
set | grep -a "^$1=" > ${TMPDIR:-/tmp}/__function_${name}_1.sh
cp -f ${TMPDIR:-/tmp}/__function_${name}_1.sh ${TMPDIR:-/tmp}/__function_${name}_2.sh
${EDITOR:-vim} ${TMPDIR:-/tmp}/__function_${name}_1.sh
diff -qwB ${TMPDIR:-/tmp}/__function_${name}_1.sh ${TMPDIR:-/tmp}/__function_${name}_2.sh >/dev/null ||
source ${TMPDIR:-/tmp}/__function_${name}_1.sh
rm -f ${TMPDIR:-/tmp}/__function_${name}_{1,2}.sh
else
echo "there is no function $name"
fi
}
__setup_ssh_agent()
{
# skip if already loaded
if [[ -n "$SSH_AGENT_PID" ]] && ps -p $SSH_AGENT_PID | grep ssh-agent >/dev/null
then return 0
fi
typeset agent_file
agent_file=~/.ssh-agent-config
if [[ -f $agent_file ]]
then source $agent_file >/dev/null
fi
if [[ -n "$SSH_AGENT_PID" ]] && ps -p $SSH_AGENT_PID | grep ssh-agent >/dev/null
then return 0
fi
ssh-agent > $agent_file
chmod 600 $agent_file
source $agent_file >/dev/null
if [[ -t 0 ]] && ! ssh-add -l | grep $HOME/.ssh/id_rsa >/dev/null
then
ssh-add
fi
}
function print_part()
{
(( $1 )) || return 0
typeset ret
ret="$1 $2"
(( $1 == 1 )) || ret="${ret}s"
printf "$ret "
}
function time_offset()
{
typeset years months days hours minutes seconds
minutes="$(( $1 / 60 % 60 ))"
hours="$(( $1 / 3600 % 24 ))"
days="$(( $1 / 86400 % 31 ))"
months="$(( $1 / 2678400 % 12 ))"
years="$(( $1 / 31536000 ))"
seconds="$(( $1 % 60 ))"
for part in year month day hour minute second
do eval "print_part \${${part}s} ${part}"
done
}
function n()
{
typeset return_status
typeset __n_time=$( date +%s )
if "$@"
then return_status=0
else return_status=$?
fi
__n_time=$(( $( date +%s ) - __n_time ))
if
(( __n_time > ${n_time:-10} ))
then
notify-send --app-name="N $1" "
Finished: $*
Took: $(time_offset __n_time)
Status: $return_status
"
fi;
return $return_status
}
__backtrace()
{
typeset counter
counter=0
while caller $counter
do : $(( counter+=1 ))
done
}
if ! which mcedit >/dev/null
then
mcedit()
{
vim "$@"
}
fi
if ! command -v rvm >/dev/null 2>&1
then
rvm()
{
echo "no rvm"
}
fi
Jump to Line
Something went wrong with that request. Please try again.