aboutsummaryrefslogtreecommitdiff
path: root/shell/utils
diff options
context:
space:
mode:
Diffstat (limited to 'shell/utils')
-rw-r--r--shell/utils120
1 files changed, 120 insertions, 0 deletions
diff --git a/shell/utils b/shell/utils
new file mode 100644
index 0000000..c597e8a
--- /dev/null
+++ b/shell/utils
@@ -0,0 +1,120 @@
+
+set_editor() {
+ if [ -z "$EDITORS" ] ; then
+ export EDITORS="ed vi vim"
+ fi
+
+ export EDITOR="$(which $EDITORS 2>/dev/null | tail -n1)"
+
+ export VISUAL="$EDITOR"
+
+ # Set an alias for our editor of choice
+ alias vi="$EDITOR"
+ alias vim="$EDITOR"
+ alias edit="$EDITOR"
+ alias e="$EDITOR"
+}
+set_pager() {
+ export PAGER="$(which cat more less 2>/dev/null | tail -n1)"
+}
+set_lang() {
+export CHARSET="$1";
+export LANG="$1";
+}
+
+# Usage debugstarttls $ipaddr:$port
+debugstarttls() {
+ openssl s_client -starttls smtp -crlf -connect "$1" "$2"
+}
+
+randmacgen() {
+ if [ "$(uname)" = "FreeBSD" ] ; then
+ LC_COLLATE=c
+ fi
+ tr -c -d '0123456789abcdef' < /dev/urandom \
+ | head -c 12 \
+ | sed 's!^M$!!;s!\-!!g;s!\.!!g;s!\(..\)!\1:!g;s!:$!!'
+ echo ""
+}
+# First argument is the interface on which to scan
+ipv6_local_hosts() {
+if ! [ -z $1 ] ; then
+ interface="$1"
+ ping6 -c 3 ff02::2%$interface \
+ | grep 'bytes from' \
+ | awk '{print $4}' \
+ | sort \
+ | uniq \
+ | sed -e's/:$//'
+else
+ echo "You need to specify an interface"
+fi
+}
+set_nocaps() {
+ setxkbmap -layout "us,de"
+ setxkbmap -option ctrl:nocaps
+ setxkbmap -option shift:breaks_caps
+ setxkbmap -option numpad:microsoft
+ setxkbmap -option grp:alt_space_toggle
+}
+# Usage: dir_oct:file_oct path
+setperms() {
+ _perm="$1"; shift
+ dir_perms=$(echo "$_perm" | awk -F: '{print $1}')
+ file_perms=$(echo "$_perm" | awk -F: '{print $2}')
+ find "$@" -type f -print0 | xargs -0 chmod "$file_perms"
+ find "$@" -type d -print0 | xargs -0 chmod "$dir_perms"
+}
+
+set_title() {
+ printf $'\033]0;'"%s"$'\007' "$1"
+}
+
+set_my_title() {
+ _load="Load Avg: $(_sys_load)"
+ _free_mem="M Free: $(_sys_memory)"
+ _uptime="Uptime: $(_sys_uptime)"
+ set_title "$(id -un)[$(hostname)] -- $_load $_free_mem $_uptime"
+}
+
+_sys_memory() {
+ ! [ -e $(which vmstat) ] && return
+ if [ `uname` = "Linux" ] ; then
+ vmstat | tail -n1 | awk '{print $4/1024}' | sed -e's/\..*$//g'
+ elif [ `uname` = "FreeBSD" ] ; then
+ vmstat | tail -n1 | awk '{print $5/1024}' | sed -e's/\..*$//g'
+ elif [ `uname` = "OpenBSD" ] ; then
+ vmstat | sed -n '$p' | awk '{print $4}' | sed 's/M$//'
+ fi
+}
+
+_sys_load() {
+ # Works on BSD too, neat.
+ uptime | sed -re's/^.*load averages?: ([0-9]+\.[0-9]+).*$/\1/g'
+}
+
+_sys_uptime() {
+ # Took awhile to figure out, but this works on BSD as well
+ uptime | sed -re's/^.*up[ ]+//g' -e's/^([^,]*),.*/\1/g' -e's/^([^ ]+)[ ]*(.).*/\1\2/g'
+}
+
+
+timestamp() {
+ date +%m.%d.%y_%H.%M.%S
+}
+
+checkSSHAgent() {
+ ssh_agent_conf="$HOME/.ssh/agent"
+ if [ -e "$ssh_agent_conf" ] ; then
+ . "$ssh_agent_conf"
+ fi
+ if ! ps -eo pid | grep -q "$SSH_AGENT_PID" \
+ || ! [ -e "$ssh_agent_conf" ] \
+ || [ -z "$SSH_AGENT_PID" ] ; \
+ then
+ ssh-agent -s | grep -v echo > "$ssh_agent_conf"
+ . "$ssh_agent_conf"
+ fi
+}
+
+