Skip to content

Commit

Permalink
Bin: migrate mhi scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mhinz committed Oct 24, 2016
1 parent be954ea commit 647783f
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
101 changes: 101 additions & 0 deletions bin/mhi
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env bash

# Configuration {{{1
mhi="$(readlink "$0")"
mhi=${mhi:=$0}
mhi="${mhi%/*}"

# Helpers {{{1
list_files() {
local path="$1"
for file in "$path"/*; do
file="${file##*/}" # basename
echo "${file%.*}" # strip ext
done
}

case $1 in
build|b) # {{{1
arg=$2 && shift 2
path="${mhi}"/build
if [[ -f "${path}/${arg}.bash" ]]; then
exec "${path}/${arg}.bash" "$@"
else
list_files "$path"
fi
;;

colors) # {{{1
for i in {0..255}; do
tput setab $i && echo -n " $i "
done
tput sgr0
echo
;;

conf|c) # {{{1
arg=$2
declare -A configs=(
[g]=~/.config/git/config
[m]=~/.muttrc
[t]=~/.tmux.conf
[v]=~/.vim/vimrc
[ze]=~/.zsh/.zshenv
[zp]=~/.zsh/.zprofile
[zr]=~/.zsh/.zshrc
)
if [[ -n $arg && -n ${configs[$arg]} ]]; then
exec "$EDITOR" "${configs[$arg]}"
else
for conf in "${!configs[@]}"; do
printf "%-6s %s\n" "$conf" "${configs[$conf]}"
done | sort
fi
;;

edit|e) # {{{1
arg=$2
path="${mhi}"/build
if [[ -n $arg ]]; then
exec "$EDITOR" "${path}/${arg}.bash"
else
list_files "$path"
fi
;;

fix) # {{{1
shift
exec "${mhi}/mhi-fix" "$@"
;;

net|n) # {{{1
shift
exec "${mhi}/mhi-net" "$@"
;;

path|p) # {{{1
IFS=:
if (( $# == 1 )); then
# shellcheck disable=SC2086
printf "%s\n" $PATH
else
shift
# shellcheck disable=SC2086
find $PATH -iname "$@" -exec ls -hl --time-style=long-iso {} + 2>/dev/null
fi
;;

*) # {{{1
cat <<MSG
build|b
colors
conf|c
edit|e
fix
net|n
path|p
MSG
;;
esac

# vim: sts=2 sw=2
22 changes: 22 additions & 0 deletions bin/mhi-fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

case $1 in
spotlight) # {{{1
hash brew 2>/dev/null || exit 1
brew linkapps
find /Applications -type l -maxdepth 1 | while read -r file; do
[[ -f "${HOME}${file}" ]] || osascript -e 'on run {f}
set dir to path to applications folder from user domain
tell application "Finder" to make alias at dir to f as POSIX file
end' "$file"
done
;;

*) # {{{1
cat <<MSG
spotlight
MSG
;;
esac

# vim: sts=2 sw=2
20 changes: 20 additions & 0 deletions bin/mhi-net
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

case $1 in
hosts) # {{{1
awk '$1 == "HostName" { print $2 }' ~/.ssh/config | cut -d. -f1 | sort ;;

irc) # {{{1
[[ -n $TMUX ]] && tmux rename-window irc
exec ssh ranok -t 'tmux attach'
;;

*) # {{{1
cat <<MSG
hosts
irc
MSG
;;
esac

# vim: sts=2 sw=2

0 comments on commit 647783f

Please sign in to comment.