Initial commit with shell functions
This commit is contained in:
parent
4d41ea9ee3
commit
876ac6a2f7
5 changed files with 96 additions and 1 deletions
19
.scripts/auto-install.sh
Executable file
19
.scripts/auto-install.sh
Executable file
|
@ -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
|
34
.scripts/fup.sh
Executable file
34
.scripts/fup.sh
Executable file
|
@ -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
|
||||||
|
}
|
20
.scripts/ip-int-convert.sh
Executable file
20
.scripts/ip-int-convert.sh
Executable file
|
@ -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))"
|
||||||
|
}
|
21
.scripts/sshtmux.sh
Executable file
21
.scripts/sshtmux.sh
Executable file
|
@ -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
|
||||||
|
}
|
|
@ -1 +1,2 @@
|
||||||
# dotfiles
|
# Dotfiles
|
||||||
|
## Useful configuration files ranging from shell scripts to configurations
|
||||||
|
|
Loading…
Reference in a new issue