Skip to content

Commit

Permalink
update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
bluemaex committed Jul 20, 2018
1 parent ab8eb16 commit 21ea2b0
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 30 deletions.
2 changes: 2 additions & 0 deletions bin/darwin/alogin → bin/alogin
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash

command -v dz >/dev/null 2>&1 || (echo "dz is not installed or in PATH"; exit 1)

UUID=$(cat ~/.dz/vms.json | jq -r '.[][] | select(.alias=="'${1}'") | select(.state=="running") | .uuid')
dz shell ${UUID:-${@}}
3 changes: 0 additions & 3 deletions bin/darwin/dnsreset

This file was deleted.

3 changes: 0 additions & 3 deletions bin/darwin/who-uses

This file was deleted.

10 changes: 10 additions & 0 deletions bin/dns-reset
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

case ${OSTYPE} in
darwin*)
killall -HUP mDNSResponder
;;
solaris*)
pkill nscd
;;
esac
11 changes: 11 additions & 0 deletions bin/who-uses
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

case ${OSTYPE} in
darwin*)
linux*)
sudo lsof -i :${1}
;;
solaris*)
lsof -o ${1}
;;
esac
4 changes: 2 additions & 2 deletions etc/.bash.d/hosts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# vim:ft=sh

# operation specific file
[ -r ${HOME}/.hosts.d/_${MS_OS} ] && source ${HOME}/.hosts.d/_${MS_OS}
[ -r ${HOME}/.hosts.d/_${MS_OS} ] && source ${HOME}/.hosts.d/_${MS_OS} || :

# hostname specific file
HOST_FILE=$(hostname | sed 's/[.].*//g')
[ -r ${HOME}/.hosts.d/${HOST_FILE} ] && source ${HOME}/.hosts.d/${HOST_FILE}
[ -r ${HOME}/.hosts.d/${HOST_FILE} ] && source ${HOME}/.hosts.d/${HOST_FILE} || :
5 changes: 2 additions & 3 deletions etc/.bash.d/login
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ fi

if [[ "$TERM" != "screen" ]]; then
## system information
echo
echo -e "${_color_blue}* ${_color_reset}${_color_bold}uname${_color_reset}"; uname -snrmp; echo

## show who is logged on
echo -e "${_color_blue}* ${_color_reset}${_color_bold}who${_color_reset}"; who -Hu; echo
fi

## fortune on every login
test -x "$(type -p fortune)" && {
command -v fortune && {
echo -e "${_color_blue}* ${_color_reset}${_color_bold}fortune${_color_reset}"; fortune -s; echo
}
} || :
50 changes: 31 additions & 19 deletions etc/.bash.d/prompt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@ function is_git_repository {
git branch > /dev/null 2>&1
}

# Detect size of git repository
function get_git_size {
git count-objects -v | sed -n 's|size-pack: \(.*\)|\1|p'
}

# Determine the branch/state information for this git repository.
function set_git_branch {
if [[ $(get_git_size) -gt 50000 ]]; then
BRANCH="(!$(git rev-parse --abbrev-ref HEAD)) "
return
fi

# Capture the output of the "git status" command.
git_status="$(git status 2> /dev/null)"
git_status="$(git status -uno 2> /dev/null)"

# Set color based on clean/staged/dirty.
if [[ ${git_status} =~ "working tree clean" ]]; then
if [[ ${git_status} =~ "nothing to commit" ]]; then
state="${_color_lime}"
elif [[ ${git_status} =~ "Changes to be committed" ]]; then
state="${_color_yellow}"
Expand Down Expand Up @@ -48,22 +58,27 @@ function set_git_branch {
BRANCH="${state}(${branch})${_color_blue}${remote}${_color_reset} "
}

# Determine active environments (python, dz, work)
function set_env () {
ENV=""
if [[ -n "${VIRTUAL_ENV}" ]]; then
ENV="${ENV}\[${_color_magenta}\]‹`basename \"$VIRTUAL_ENV\"`›\[${_color_reset}\] "
fi
if [[ -n "${WORK_VIRTUALENV}" ]]; then
ENV="${ENV}\[${_color_blue}\]‹${WORK_VIRTUALENV}›\[${_color_reset}\] "
fi
if [[ -n "${DZ_VIRTUALENV}" ]]; then
ENV="${ENV}\[${_color_yellow}\]‹${DZ_VIRTUALENV}›\[${_color_reset}\] "
fi
}

# Return the prompt symbol to use, colorized based on the return value of the
# previous command.
function set_prompt_symbol () {
if test $1 -eq 0 ; then
PROMPT_SYMBOL="»"
else
PROMPT_SYMBOL="\[${_color_red}\]»\[${_color_reset}\]"
fi
}

# Determine active Python virtualenv details.
function set_virtualenv () {
if test -z "$VIRTUAL_ENV" ; then
PYTHON_VIRTUALENV=""
else
PYTHON_VIRTUALENV="\[${_color_magenta}\]‹`basename \"$VIRTUAL_ENV\"`›\[${_color_reset}\] "
PROMPT_SYMBOL="\[${_color_red}\][${1}] »\[${_color_reset}\]"
fi
}

Expand All @@ -74,33 +89,30 @@ function set_bash_prompt () {
set_prompt_symbol $?

# Set the PYTHON_VIRTUALENV variable.
set_virtualenv
set_env

# Set the BRANCH variable.
BRANCH=''
if [ -z "${DISABLE_GIT_PROMPT}" ]; then
if is_git_repository ; then
set_git_branch
else
BRANCH=''
fi
else
BRANCH=''
fi

# Change the window title of X terminals
echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"

# Set the bash prompt variable.
if [[ ${EUID} == 0 ]] ; then
PS1="${PYTHON_VIRTUALENV}\[${_color_red}\][\u@\h]\[${_color_reset}\]:\[${_color_blue}\]\w ${BRANCH}#\[${_color_reset}\] "
PS1="${PYTHON_VIRTUALENV}\[${_color_red}\][\u@\h]\[${_color_reset}\]:\[${_color_blue}\]\w ${BRANCH}#\[${_color_reset} \D{%T}\] "
PS2='root %> '
else
if [ -n "${SSH_CLIENT}" ] || [ -n "${SSH_TTY}" ]; then
PS1="\[${_color_blue}\][\u@\h]\[${_color_reset}\] ${PYTHON_VIRTUALENV}${BRANCH}\[${_color_green}\]\w\[${_color_reset}\]
${PROMPT_SYMBOL} "
PS2='%> '
else
PS1="\[${_color_orange}\][\u@\h]\[${_color_reset}\] ${PYTHON_VIRTUALENV}${BRANCH}\[${_color_green}\]\w\[${_color_reset}\]
PS1="\[${_color_orange}\][\u@\h]\[${_color_reset}\] ${PYTHON_VIRTUALENV}${BRANCH}\[${_color_green}\]\w\[${_color_reset} \D{%T}\]
${PROMPT_SYMBOL} "
PS2='%> '
fi
Expand Down

0 comments on commit 21ea2b0

Please sign in to comment.