install.fairie/home/dot_config/shell/functions.sh.tmpl

145 lines
4.2 KiB
Cheetah
Raw Normal View History

#!/usr/bin/env sh
# @file Shell Functions
# @brief Houses the functions that are included by `~/.bashrc` and `~/.zshrc`
# @description
# This script is included by `~/.bashrc` and `~/.zshrc` to provide various commands and functions.
# Install WebDriverAgent on iOS device
appiumwebdriver() {
# read -r "Enter the UDID of the device you wish to install WebDriverAgent on: " UDID_INPUT
mkdir -p Resources/WebDriverAgent.bundle
bash ./Scripts/bootstrap.sh -d
cd /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent || return
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination "id=${UDID_INPUT}" test
}
Update dotfiles/.local/share/chezmoi/home/.chezmoiexternal.toml, dotfiles/.local/share/chezmoi/home/.chezmoiremove, dotfiles/.local/share/chezmoi/home/private_dot_config/shell/functions, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_before_10_install-darwin-packages.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_after_20-configure-darwin-shell.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_after_10_configure-darwin.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoidata.yaml, dotfiles/.local/share/chezmoi/home/private_dot_config/shell/exports, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_after_15_install-asdf-packages.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_after_20_install-helm-plugins.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_after_10_install-aqua-packages.sh.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_after_30_install-krew-plugins.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_after_40_install-rust-toolchain.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_after_99_bootstrap-z4h.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/archlinux/run_onchange_before_10_install-archlinux-packages.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/ubuntu/run_onchange_before_10_install-ubuntu-packages.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoitemplates/universal/essential-packages, dotfiles/.local/share/chezmoi/home/dot_local/bin/symlink_bat.tmpl, dotfiles/.local/share/chezmoi/home/dot_local/bin/symlink_fd.tmpl, dotfiles/.local/share/chezmoi/home/dot_local/bin/symlink_readlink.tmpl
2022-11-24 02:42:17 -08:00
asdf-update () {
asdf update > /dev/null 2>&1
asdf plugin update --all > /dev/null 2>&1
diff <(cat ~/.tool-versions | awk '{print $1}' | xargs -I {} bash -c 'echo {} $(asdf latest {})') <(cat ~/.tool-versions)
}
# Change directories and view contents at the same time
cl() {
DIR="$*"
# if no DIR given, go home
if [ $# -lt 1 ]; then
DIR=$HOME
fi
builtin cd "${DIR}" &&
# use your preferred ls command
ls -F --color=auto
}
# Safer cp with progress bar and backup to /tmp
cpv() {
rsync -pogbr -hhh --backup-dir="/tmp/rsync-${USERNAME}" -e /dev/null --progress "$@"
}
# Checks status of a website on downforeveryoneorjustme.com
down4me() {
curl -s "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
}
# Easier version of find command
find() {
if [ $# = 1 ]; then
# shellcheck disable=SC2145
command find . -iname "*$@*"
else
command find "$@"
fi
}
# Opens current repository in browser
gitopen() {
git remote -v | head -n 1 | awk -F "@" '{print $2}' | awk -F " " '{print $1}' | sed 's/:/\//g' | sed 's/.git//g' | awk '{print "http://"$1}' | xargs open
}
# Open Mac OS X desktop on a Linux machine
macosx() {
docker run -it --device /dev/kvm -p 50922:10022 -v /tmp/.X11-unix:/tmp/.X11-unix -e "DISPLAY=${DISPLAY:-:0.0}" sickcodes/docker-osx:big-sur
}
# Generate a random string of X length
randomstring() {
if [ -z "$1" ]; then
head /dev/urandom | tr -dc A-Za-z0-9 | head -c "$1"
else
echo "Pass the number of characters you would like the string to be. Example: randomstring 14"
fi
}
# Reset Docker to factory settings
resetdocker() {
set +e
CONTAINER_COUNT="$(docker ps -a -q | wc -l)"
if [ "$CONTAINER_COUNT" -gt 0 ]; then
docker stop "$(docker ps -a -q)"
docker rm "$(docker ps -a -q)"
fi
VOLUME_COUNT="$(docker volume ls -q | wc -l)"
if [ "$VOLUME_COUNT" -gt 0 ]; then
docker volume rm "$(docker volume ls -q)"
fi
NETWORK_COUNT="$(docker network ls -q | wc -l)"
if [ "$NETWORK_COUNT" -gt 0 ]; then
docker network rm "$(docker network ls -q)"
fi
docker system prune -a --force
}
# ripgrep-all
rgafzf() {
RG_PREFIX="rga --files-with-matches"
local file
file="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX '$1'" \
fzf --sort --preview="[[ ! -z {} ]] && rga --pretty --context 5 {q} {}" \
--phony -q "$1" \
--bind "change:reload:$RG_PREFIX {q}" \
--preview-window="70%:wrap"
)" &&
echo "opening $file" &&
xdg-open "$file"
}
# Easy file sharing from the command line, using transfer.sh
transfer() {
if [ $# -eq 0 ]; then
echo -e "No arguments specified.\nUsage:\n transfer <file|directory>\n ... | transfer <file_name>" >&2
return 1
fi
if tty -s; then
file="$1"
file_name=$(basename "$file")
if [ ! -e "$file" ]; then
echo "$file: No such file or directory" >&2
return 1
fi
if [ -d "$file" ]; then
file_name="$file_name.zip"
(cd "$file" && zip -r -q - .) | curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name" | tee /dev/null,
else
curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name" <"$file" | tee /dev/null
fi
else
file_name=$1
curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name" | tee /dev/null
fi
}
Update dotfiles/.local/share/chezmoi/home/.chezmoiexternal.toml, dotfiles/.local/share/chezmoi/home/.chezmoiremove, dotfiles/.local/share/chezmoi/home/private_dot_config/shell/functions, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_before_10_install-darwin-packages.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_after_20-configure-darwin-shell.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_after_10_configure-darwin.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoidata.yaml, dotfiles/.local/share/chezmoi/home/private_dot_config/shell/exports, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_after_15_install-asdf-packages.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_after_20_install-helm-plugins.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_after_10_install-aqua-packages.sh.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_after_30_install-krew-plugins.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_after_40_install-rust-toolchain.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_after_99_bootstrap-z4h.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/archlinux/run_onchange_before_10_install-archlinux-packages.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/ubuntu/run_onchange_before_10_install-ubuntu-packages.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoitemplates/universal/essential-packages, dotfiles/.local/share/chezmoi/home/dot_local/bin/symlink_bat.tmpl, dotfiles/.local/share/chezmoi/home/dot_local/bin/symlink_fd.tmpl, dotfiles/.local/share/chezmoi/home/dot_local/bin/symlink_readlink.tmpl
2022-11-24 02:42:17 -08:00
update-all() {
brew update
brew upgrade
brew upgrade --cask --greedy
brew cleanup --prune=1
asdf update || true
asdf plugin-update --all
rustup self update || true
rustup update || true
npm update -g || true
chezmoi upgrade
z4h update
}