install.fairie/dotfiles/.local/functions
2022-10-31 21:52:44 +00:00

106 lines
3.3 KiB
Text

# 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
}
# 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
}
# 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
}
# 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
}
### Helpers for MOTD
dnf() {
command dnf "$@"
mkdir -p "$HOME/.local/labs" > /dev/null
command dnf updateinfo list --security --available | grep '/Sec. ' | wc -l > "$HOME/.local/labs/dnf-updates-sec" &
command dnf list updates | grep updates | wc -l > "$HOME/.local/labs/dnf-updates-reg" &
}