Commit dee8eeb9 authored by Hermann Mayer's avatar Hermann Mayer

BashRC: Split development helpers. Added new development/docker helpers.

parent 7f8443ec
......@@ -18,7 +18,11 @@ bashrcComponent['completions']=1
# +-------------------------------------------------
bashrcComponent['helper/commons']=1
bashrcComponent['helper/development']=1
bashrcComponent['helper/development/commons']=1
bashrcComponent['helper/development/watch']=1
bashrcComponent['helper/development/docker']=1
bashrcComponent['helper/development/git']=1
bashrcComponent['helper/development/svn']=1
bashrcComponent['helper/archives']=1
bashrcComponent['helper/features']=1
bashrcComponent['helper/distro/slackware']=0
......
......@@ -29,4 +29,3 @@ alias less='less -R'
complete -W "$(cat "${HOME}/.bash_history" | egrep '^ssh |^scp ' | grep '\.' | egrep '^[^0-9]' | sort | uniq | sed 's/^ssh //' | sed 's/ $//g' | sed 's/^/\"/' | sed 's/$/\"/');" ssh
complete -W "$(cat "${HOME}/.bash_history" | egrep '^ssh |^scp ' | grep '\.' | egrep '^[^0-9]' | sort | uniq | sed 's/^ssh //' | sed 's/ $//g' | sed 's/^/\"/' | sed 's/$/\"/');" scp
......@@ -27,4 +27,3 @@ shopt -s globstar
# Auto "cd" when entering just a path
shopt -s autocd
......@@ -68,4 +68,3 @@ function print8Colors()
LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.svgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01; 35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:'
export LS_COLORS
......@@ -6,4 +6,3 @@
# +-------------------------------------------------
# | Commons
# +-------------------------------------------------
......@@ -22,4 +22,3 @@ _bashrc()
}
complete -F _bashrc -o bashdefault bashrc
......@@ -10,7 +10,8 @@
# Extglob is a dependency for the extract method
shopt -s extglob
function extract() {
function extract()
{
local c e i
(($#)) || return
......@@ -53,10 +54,10 @@ function extract() {
return $e
}
function extractRar() {
function extractRar()
{
ls *.part01.rar *.part001.rar *.part0001.rar 2>/dev/null | while read FILE; do
unrar e "$FILE";
done;
}
......@@ -23,4 +23,3 @@ function secondsFormat()
{
printf ""%dh:%dm:%ds"\n" $(($1/3600)) $(($1%3600/60)) $(($1%60))
}
#!/bin/bash
#
# @author Hermann Mayer <hermann.mayer92@gmail.com>
# @name development.sh
# +-------------------------------------------------
# | Development/Common Helper
# +-------------------------------------------------
function debughtml()
{
cat - | xmllint --format --html --recover - | highlight --out-format=xterm256 -S xml -- | less -R
}
function debugxml()
{
cat - | xmllint --format --recover - | highlight --out-format=xterm256 -S xml -- | less -R
}
function generateMAC()
{
echo $(dd bs=1 count=6 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"' | sed 's/^-//g')
}
#!/bin/bash
#
# @author Hermann Mayer <hermann.mayer92@gmail.com>
# @name development.sh
# +-------------------------------------------------
# | Development/Docker Helper
# +-------------------------------------------------
function docker-remove-stopped-containers()
{
if [ -z "$(docker ps -a -q)" ]; then
echo 'No stopped containers found.'
return 0
fi
docker rm --volumes --force $(docker ps -a -q)
}
function docker-remove-untagged-images()
{
docker rmi $(docker images -a | grep "^<none>" | awk '{print $3}')
}
function docker-remove-all-images()
{
docker rmi --force $(docker images -a | awk '{print $3}')
}
# 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}
}
function docker-stop-all()
{
for line in `docker ps | awk '{print $1}' | grep -v CONTAINER`; do
docker kill -s 9 ${line}
done
}
function docker-user-container-here()
{
if [ -z "${1}" ]; then
echo 'No image was specified.'
echo 'Usage: docker-container-here IMAGE'
echo
echo 'Additional environment variables:'
echo ' PORT Host port to open, default: random'
echo ' CONTAINER_PORT Container port, default: 3000'
exit 1
fi
if [ -z "${PORT}" ]; then
local PORT=$RANDOM
fi
if [ -z "${CONTAINER_PORT}" ]; then
local CONTAINER_PORT=3000
fi
echo "Bind host port ${PORT} to container port ${CONTAINER_PORT}"
docker run --rm -i -v `pwd`:/data -e USER=`whoami` -p 0.0.0.0:${PORT}:${CONTAINER_PORT} \
-u "`id -u`:`id -u`" -t "${1}" \
/bin/bash -c 'echo "export PS1=\"\${debian_chroot:+(\$debian_chroot)}\${USER}@\h:\w\$ \";
alias l=\"ls -lisa\"; alias x=\"exit\"" > /tmp/.bashrc;
cd /data; bash --rcfile /tmp/.bashrc -i'
}
function docker-user-container-run()
{
if [ -z "${1}" ]; then
echo 'No image was specified.'
echo 'Usage: docker-container-run IMAGE'
exit 1
fi
local IMAGE="${1}"
shift
docker run --rm -i -v `pwd`:/data -e USER=`whoami` \
-u "`id -u`:`id -u`" -t "${IMAGE}" \
/bin/bash -c "cd /data; $*"
}
......@@ -4,95 +4,9 @@
# @name development.sh
# +-------------------------------------------------
# | Development Helper
# | Development/Git Helper
# +-------------------------------------------------
function echoColorizedSVNLine()
{
line=$1
skipX=$2
done="false"
if [[ "$done" == false && "$line" =~ ^M.* ]]; then
echo -e "$bldylw$line\E[0m"
done="true"
fi
if [[ "$done" == false && "$line" =~ ^D.* ]]; then
echo -e "$txtred$line\E[0m"
done="true"
fi
if [[ "$done" == false && "$line" =~ ^A.* ]]; then
echo -e "$bldgrn$line\E[0m"
done="true"
fi
if [[ "$done" == false && "$line" =~ ^C.* ]]; then
echo -e "$bldred$line\E[0m"
done="true"
fi
if [[ "$done" == false && "$line" =~ ^\?.* ]]; then
echo -e "$bldpur$line\E[0m"
done="true"
fi
if [[ "$done" == false && "$line" =~ ^\!.* ]]; then
echo -e "\E[01;31m$line\E[0m"
done="true"
fi
if [[ "$done" == false && "$line" =~ ^X.* ]]; then
if [[ "$skipX" == false ]]; then
echo -e "\E[01;30m$line\E[0m"
fi
done="true"
fi
if [[ "$done" == false && "$line" =~ ^L.* ]]; then
if [[ "$skipX" == false ]]; then
echo -e "\E[01;30m$line\E[0m"
fi
done="true"
fi
if [[ "$done" == false && "$line" =~ ^S.* ]]; then
echo -e "\E[01;30m$line\E[0m"
done="true"
fi
if [[ "$done" == false ]]; then
echo -e "$line"
fi
}
function svn()
{
svnPath=`which svn`
local operation=$1
shift
if [ 'status' == "${operation}" ]; then
$svnPath status "$@" | while read line; do echoColorizedSVNLine "${line}" "false"; done
elif [ 'statusx' == "${operation}" ]; then
$svnPath status "$@" | while read line; do echoColorizedSVNLine "${line}" "true"; done
elif [ 'log' == "${operation}" ]; then
$svnPath log "$@" | sed -e 's/^-\+$/\0/' -e 's/^r[0-9]\+.\+$/\0/' | less -R
else
$svnPath "${operation}" "$@"
fi
}
function debughtml()
{
cat - | xmllint --format --html --recover - | highlight --out-format=xterm256 -S xml -- | less -R
}
function debugxml()
{
cat - | xmllint --format --recover - | highlight --out-format=xterm256 -S xml -- | less -R
}
function git-current-commit()
{
local commit=$(git log --pretty="%h" -n1 HEAD)
......@@ -131,12 +45,6 @@ function git-stat()
) | column -t
}
function svn-current-revision()
{
local rev=$(svn info | grep ' Rev' | cut -d ':' -f2)
echo -e "Current svn revision: ${bldylw}${rev}${txtrst}"
}
function gitrs()
{
mpx git --no-pager ${@}
......@@ -182,31 +90,6 @@ function git-log-full()
git log --decorate --stat --graph --pretty=format:"%d %Cgreen%h%Creset (%ar - %Cred%an%Creset), %s%n"
}
function generateMAC()
{
echo $(dd bs=1 count=6 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"' | sed 's/^-//g')
}
function docker-remove-stopped-containers()
{
if [ -z "$(docker ps -a -q)" ]; then
echo 'No stopped containers found.'
return 0
fi
docker rm $(docker ps -a -q)
}
function docker-remove-untagged-images()
{
docker rmi $(docker images -a | grep "^<none>" | awk '{print $3}')
}
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/ \
......@@ -230,21 +113,3 @@ function git-branch-status()
) | 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}
}
#!/bin/bash
#
# @author Hermann Mayer <hermann.mayer92@gmail.com>
# @name development.sh
# +-------------------------------------------------
# | Development/SVN Helper
# +-------------------------------------------------
function echoColorizedSVNLine()
{
line=$1
skipX=$2
done="false"
if [[ "$done" == false && "$line" =~ ^M.* ]]; then
echo -e "$bldylw$line\E[0m"
done="true"
fi
if [[ "$done" == false && "$line" =~ ^D.* ]]; then
echo -e "$txtred$line\E[0m"
done="true"
fi
if [[ "$done" == false && "$line" =~ ^A.* ]]; then
echo -e "$bldgrn$line\E[0m"
done="true"
fi
if [[ "$done" == false && "$line" =~ ^C.* ]]; then
echo -e "$bldred$line\E[0m"
done="true"
fi
if [[ "$done" == false && "$line" =~ ^\?.* ]]; then
echo -e "$bldpur$line\E[0m"
done="true"
fi
if [[ "$done" == false && "$line" =~ ^\!.* ]]; then
echo -e "\E[01;31m$line\E[0m"
done="true"
fi
if [[ "$done" == false && "$line" =~ ^X.* ]]; then
if [[ "$skipX" == false ]]; then
echo -e "\E[01;30m$line\E[0m"
fi
done="true"
fi
if [[ "$done" == false && "$line" =~ ^L.* ]]; then
if [[ "$skipX" == false ]]; then
echo -e "\E[01;30m$line\E[0m"
fi
done="true"
fi
if [[ "$done" == false && "$line" =~ ^S.* ]]; then
echo -e "\E[01;30m$line\E[0m"
done="true"
fi
if [[ "$done" == false ]]; then
echo -e "$line"
fi
}
function svn()
{
svnPath=`which svn`
local operation=$1
shift
if [ 'status' == "${operation}" ]; then
$svnPath status "$@" | while read line; do echoColorizedSVNLine "${line}" "false"; done
elif [ 'statusx' == "${operation}" ]; then
$svnPath status "$@" | while read line; do echoColorizedSVNLine "${line}" "true"; done
elif [ 'log' == "${operation}" ]; then
$svnPath log "$@" | sed -e 's/^-\+$/\0/' -e 's/^r[0-9]\+.\+$/\0/' | less -R
else
$svnPath "${operation}" "$@"
fi
}
function svn-current-revision()
{
local rev=$(svn info | grep ' Rev' | cut -d ':' -f2)
echo -e "Current svn revision: ${bldylw}${rev}${txtrst}"
}
#!/bin/bash
#
# @author Hermann Mayer <hermann.mayer92@gmail.com>
# @name development.sh
# +-------------------------------------------------
# | Development/Watch Helper
# +-------------------------------------------------
function watch-dmesg()
{
watch -c -n1 "dmesg --color=always | tail -n `$(($(tput lines)-5))`"
}
function watch-make-test()
{
while [ 1 ]; do
inotifywait --quiet -r `pwd` -e close_write --format '%e -> %w%f'
make test
done
}
function watch-run()
{
while [ 1 ]; do
inotifywait --quiet -r `pwd` -e close_write --format '%e -> %w%f'
$@
done
}
......@@ -42,4 +42,3 @@ function fileinpkg()
}
fi
......@@ -62,4 +62,3 @@ function d()
command cd "${next}"
fi
}
......@@ -289,4 +289,3 @@ function cdtmp()
mkdir "/tmp/${name}"
cd "/tmp/${name}"
}
......@@ -52,4 +52,3 @@ function finder()
find . -type f -exec grep -n -H --colour=auto -i "${@}" {} \;
}
......@@ -17,9 +17,9 @@ function userinfo()
ldapsearch \
-h ldap.l.unister.lan \
-Z \
-D "uid=${LDAP_USERNAME},ou=Users, dc=unister, dc=lan" \
-w "${LDAP_PASSWORD}" -b "uid=${1},ou=Users, dc=unister, dc=lan" \
| grep -E "${1}|$" | egrep -i '(mail|cn|sn|o|telephoneNumber|givenName|standorte|uid|rfid|description|departmentLocation):' | sort \
-D "uid=${LDAP_USERNAME}, ${LDAP_SUFFIX}" \
-w "${LDAP_PASSWORD}" -b "uid=${1}, ${LDAP_SUFFIX}" \
| grep -E "${1}|$" | egrep -i "${LDAP_SEARCH}" | sort \
| while read line; do
if [[ $c -eq 0 ]]; then
......@@ -54,4 +54,3 @@ function userinfo()
}
fi
......@@ -91,4 +91,3 @@ function checkSMART()
fi
done < <(smartctl -a "$@" | egrep "^ 5|^ 10|^184|^188|^196|^197|^198|^201|^230" | egrep " [0-9]{2,}$|$")
}
......@@ -22,4 +22,3 @@ bind '"\e\e[D": backward-word'
# use arrow keys to fast search
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
......@@ -59,4 +59,3 @@ fi
# Try to keep environment pollution down, EPA loves us.
unset use_color safe_term match_lhs
......@@ -243,4 +243,3 @@ if [ "${1}" != '--no-run' ]; then
fi
fi
fi
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