diff --git a/.scripts/auto-install.sh b/.scripts/auto-install.sh new file mode 100755 index 0000000..cfd14cd --- /dev/null +++ b/.scripts/auto-install.sh @@ -0,0 +1,19 @@ +# auto install oh-my-zsh and tpm +if which git > /dev/null 2>&1; then + # if oh-my-zsh is not installed, autoinstall it + if [ ! -e "${ZSH}" ]; then + echo 'oh-my-zsh is missing... autoinstalling now' + sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" + fi + + TPM="${HOME}/.tmux/plugins/tpm" + # if tpm (Tmux Plugin Manager) is not installed, autoinstall it + if [ ! -e "${TPM}" ]; then + git clone https://github.com/tmux-plugins/tpm "${TPM}" + fi + + if ! egrep -q 'run.*tpm' "${HOME}/.tmux.conf" 2>&1; then + echo 'adding TPM to ~/.tmux.conf' + echo "run '${HOME}/.tmux/plugins/tpm/tpm'" >> "${HOME}/.tmux.conf" + fi +fi diff --git a/.scripts/fup.sh b/.scripts/fup.sh new file mode 100755 index 0000000..cf87176 --- /dev/null +++ b/.scripts/fup.sh @@ -0,0 +1,34 @@ +# fup uploads a given file to file.io +fup() { + if [ -z "${1}" -o ! -f "${1}" ]; then + echo 'provide a valid file path' + return 1 + fi + + local cmd="-F 'file=@${1}' https://file.io/" + + if [ ! -z "${2}" ]; then + cmd="${cmd}\?expires=${2}" + fi + + local json_return="$(eval "curl ${cmd}")" + if [ $? -ne 0 ]; then + echo 'Curl failed' + return 1 + fi + + if [ $(echo "${json_return}" | grep -c '"success":false') -ne 0 ]; then + echo "${json_return}" + return 1 + fi + + echo "https://file.io/$(echo "${json_return}" | sed 's/.*key":"//' | sed 's/".*//')" + + if [ $(echo "${json_return}" | grep -c '"expiry":') -eq 0 ]; then + echo 'Expires in 14 days' + else + echo "Expires in $(echo "${json_return}" | sed 's/.*expiry":"//' | sed 's/".*//')" + fi + + return 0 +} diff --git a/.scripts/ip-int-convert.sh b/.scripts/ip-int-convert.sh new file mode 100755 index 0000000..ad4c4b8 --- /dev/null +++ b/.scripts/ip-int-convert.sh @@ -0,0 +1,20 @@ +# convert integer to IP +int2ip () { + local ip dec=$@ + for e in {3..0} + do + ((octet = dec / (256 ** e) )) + ((dec -= octet * 256 ** e)) + ip+=$delim$octet + delim=. + done + printf '%s\n' "$ip" + unset delim +} + +# convert IP to integer +ip2int () { + local a b c d ip=$@ + IFS=. read -r a b c d <<< "$ip" + printf '%d\n' "$((a * 256 ** 3 + b * 256 ** 2 + c * 256 + d))" +} diff --git a/.scripts/sshtmux.sh b/.scripts/sshtmux.sh new file mode 100755 index 0000000..5d9e015 --- /dev/null +++ b/.scripts/sshtmux.sh @@ -0,0 +1,21 @@ +# create splits in a tmux session for each ssh host +sshtmux() { + if [ -z "${TMUX}" ]; then + echo "This must be executed inside of a tmux session" + return 1 + fi + + if [ -z "${1}" ]; then + echo "Please provide of list of hosts separated by spaces" + return 1 + fi + + tmux new-window "ssh" + for i in ${@}; do + tmux split-window -h "ssh -o StrictHostKeyChecking=no $i" + tmux select-layout tiled > /dev/null + sleep .1s + done + + tmux select-pane -t 0 +} diff --git a/README.md b/README.md index 27ef622..c40705c 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# dotfiles \ No newline at end of file +# Dotfiles +## Useful configuration files ranging from shell scripts to configurations