Commit 7f8443ec authored by Hermann Mayer's avatar Hermann Mayer

BashRC: Added new Git and Docker helper functions.

parent 7578f858
......@@ -206,3 +206,45 @@ function docker-remove-all-images()
{
docker rmi --force $(docker images -a | awk '{print $3}')
}
function git-branch-last-commitdate()
{
git for-each-ref --sort=-committerdate refs/remotes/origin/ \
--format='%(committerdate:short) %(committeremail) %(refname:short) %(upstream:short)'
}
# Based on https://gist.github.com/jehiah/1288596
function git-branch-status()
{
TMP_FILE=$(mktemp)
(
git-branch-last-commitdate | while read committerdate authoremail local remote; do
[ -z "$remote" ] && remote="origin/master"
git rev-list --left-right ${local}...${remote} -- 2>/dev/null \
>${TMP_FILE} || continue
LEFT_AHEAD=$(grep -c '^<' ${TMP_FILE})
RIGHT_AHEAD=$(grep -c '^>' ${TMP_FILE})
echo "$local | (ahead $LEFT_AHEAD) | (behind $RIGHT_AHEAD) \
| $remote | $committerdate | $authoremail"
done
) | column -t -s '|'
rm ${TMP_FILE}
}
# Based on http://www.commandlinefu.com/commands/view/13708/show-memory-usage-of-all-docker-lxc-containers
function docker-memory-usage()
{
TMP_FILE=$(mktemp)
(
echo 0 > ${TMP_FILE}
for line in `docker ps | awk '{print $1}' | grep -v CONTAINER`; do
name=$(docker ps | grep $line | awk '{printf $NF" "}')
mem=$(echo $(( `cat /sys/fs/cgroup/memory/system.slice/docker-$line*/memory.usage_in_bytes` / 1024 / 1024 )))
all=$[$(cat $TMP_FILE) + $mem]
echo $all > ${TMP_FILE}
printf '%s | %dMB\n' $name $mem
done | sort -rh -k3
printf '| -----\nMemory summary | %dMB' $(cat $TMP_FILE)
) | column -t -s '|'
rm ${TMP_FILE}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment