From 44e1beab9f1042010d765fb0db6f79da9cbf2c6a Mon Sep 17 00:00:00 2001 From: Brian Zalewski Date: Mon, 31 Oct 2022 01:27:37 +0000 Subject: [PATCH] Update dotfiles/.profile, dotfiles/.local/aliases, dotfiles/.local/functions --- dotfiles/.local/aliases | 115 ++++++++++++++++ dotfiles/.local/functions | 98 +++++++++++++ dotfiles/.profile | 280 +++++--------------------------------- 3 files changed, 244 insertions(+), 249 deletions(-) create mode 100644 dotfiles/.local/aliases create mode 100644 dotfiles/.local/functions diff --git a/dotfiles/.local/aliases b/dotfiles/.local/aliases new file mode 100644 index 00000000..ba83b8c6 --- /dev/null +++ b/dotfiles/.local/aliases @@ -0,0 +1,115 @@ +# Create an Authelia password hash +alias autheliapassword='docker run authelia/authelia:latest authelia hash-password' + +# Shows IP addresses that are currently banned by fail2ban +alias banned='sudo zgrep "Ban" /var/log/fail2ban.log*' + +alias connections='nm-connection-editor' + +# Make copy command verbose +alias cp='cp -v' + +# Copies with a progress bar +alias cpv='rsync -ah --info=progress2' + +# Download a file +alias download='curl --continue-at - --location --progress-bar --remote-name --remote-time' + +# Download a website +alias downloadsite='wget --mirror -p --convert-links -P' + +# Flush DNS +alias flushdns='sudo systemd-resolve --flush-caches && sudo systemd-resolve --statistics' + +# FontBook for macOS +alias fontbook="open -b com.apple.FontBook" + +# Get the possible GRUB resolutions +alias grubresolutions='sudo hwinfo --framebuffer' + +# Execute git command with sudo priviledges while retaining .gitconfig +alias gsudo='sudo git -c "include.path="${XDG_CONFIG_DIR:-$HOME/.config}/git/config\" -c \"include.path=$HOME/.gitconfig\"' + +# Create hashed password for Ansible user creation +alias hashpassword='mkpasswd --method=sha-512' + +# Show full output when using ls +alias ls='ls -AlhF --color=auto' + +# Create parent directories automatically +alias mkdir='mkdir -pv' + +# Make mount command output readable +alias mount='mount | column -t' + +# Make mv command verbose +alias mv='mv -v' + +# Show IP address +alias myip='curl http://ipecho.net/plain; echo' + +# Shows local IP addresses +alias mylocalip="ifconfig | grep -Eo 'inet (addr:|adr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'" + +# Show open ports +alias ports='sudo netstat -tulanp' + +# Shuts down the computer, skipping the shutdown scripts +alias poweroff='sudo /sbin/poweroff' + +# Open the Rclone web GUI +alias rclonegui='rclone rcd --rc-web-gui --rc-user=admin --rc-pass=pass --rc-serve' + +# Reboot the computer +alias reboot='sudo /sbin/reboot' + +# Make rm command verbose +alias rm='rm -vi' + +# Launch the Python Simple HTTP Server +alias serve='python -m SimpleHTTPServer' + +# Generate a SHA1 digest +alias sha1='openssl sha1' + +# Shutdown the computer +alias shutdown='sudo /sbin/shutdown' + +# Speed test +alias speedtest='wget -O /dev/null http://speedtest.wdc01.softlayer.com/downloads/test10.zip' + +# Shortcut for config file +alias sshconfig='${EDITOR:code} ~/.ssh/config' + +# Pastebin +alias sprunge='curl -F "sprunge=<-" http://sprunge.us' + +# Disable Tor for current shell +alias toroff='source torsocks off' + +# Enable Tor for current shell +alias toron='source torsocks on' + +# Test Tor connection +alias tortest='curl --socks5-hostname 127.0.0.1:9050 --silent https://check.torproject.org/ | head -25' + +# Unban IP address (e.g. unban 10.14.24.14) +alias unban='sudo fail2ban-client set sshd unbanip' + +# Recursively encrypts files using Ansible Vault +alias unvaultdir='find . -type f -printf "%h/\"%f\" " | xargs ansible-vault decrypt' + +# Alias for updating software +alias update='sudo apt-get update && sudo apt-get upgrade' + +# Sets v as an alias for vim +alias v='vim' + +# Recursively encrypts files using Ansible Vault +alias vaultdir='find . -type f -printf "%h/\"%f\" " | xargs ansible-vault encrypt' + +# Shows nice looking report of weather +alias weather='curl -A curl wttr.in' + +# Change .wget-hsts file location +alias wget="wget --hsts-file ~/.config/.wget-hsts" diff --git a/dotfiles/.local/functions b/dotfiles/.local/functions new file mode 100644 index 00000000..b7e088eb --- /dev/null +++ b/dotfiles/.local/functions @@ -0,0 +1,98 @@ +# 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 \n ... | transfer " >&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 +} diff --git a/dotfiles/.profile b/dotfiles/.profile index 07f89399..3f0bd1b2 100644 --- a/dotfiles/.profile +++ b/dotfiles/.profile @@ -20,6 +20,14 @@ export LESSHISTFILE=- ### Line Wrap setterm -linewrap on 2>/dev/null +# Aliases / Functions +if [ -f "$HOME/.local/aliases" ]; then + . "$HOME/.local/aliases" +fi +if [ -f "$HOME/.local/functions" ]; then + . "$HOME/.local/functions +fi + ### Bash / ZSH if [ "$0" = 'bash' ] || [ "$0" = '/bin/bash' ] || [ "$SHELL" = '/bin/bash' ] || [ "$0" = 'zsh' ] || [ "$0" = '/bin/zsh' ] || [ "$SHELL" = '/bin/zsh' ]; then ### OS Detection @@ -82,142 +90,32 @@ if [ "$0" = 'bash' ] || [ "$0" = '/bin/bash' ] || [ "$SHELL" = '/bin/bash' ] || fi ### MOTD - if [ -f "$HOME/.local/motd.sh" ] && { [ -n "$SSH_CONNECTION" ] && [ "$SHLVL" -eq 1 ] && [[ $- == *i* ]]; } || command -v qubes-vmexec > /dev/null || command -v qubes-dom0-update > /dev/null || { [ -d /Applications ] && [ -d /System ]; }; then - if { [ -z "$MOTD" ] || [ "$MOTD" -ne 0 ]; } && [[ "$(hostname)" != *'-minimal' ]]; then - . "$HOME/.local/motd.sh" - - # TODO - -- services - if [ -n "$SSH_CONNECTION" ]; then - # SSH - bash_motd --banner --processor --memory --diskspace --services --docker --updates --letsencrypt --login - elif command -v qubes-vmexec > /dev/null; then - # Qubes AppVM - bash_motd --banner --memory --diskspace --docker - elif command -v qubes-dom0-update > /dev/null; then - # Qubes dom0 - bash_motd --banner --updates - elif [ -d /Applications ] && [ -d /System ]; then - # macOS - bash_motd --banner - else - bash_motd --banner --processor --memory --diskspace --services --docker --updates --letsencrypt --login + # Add file named .hushlogin in the user's home directory to disable the MOTD + if [ ! -f ~/.hushlogin ]; then + if [ -f "$HOME/.local/motd.sh" ] && { [ -n "$SSH_CONNECTION" ] && [ "$SHLVL" -eq 1 ] && [[ $- == *i* ]]; } || command -v qubes-vmexec > /dev/null || command -v qubes-dom0-update > /dev/null || { [ -d /Applications ] && [ -d /System ]; }; then + if { [ -z "$MOTD" ] || [ "$MOTD" -ne 0 ]; } && [[ "$(hostname)" != *'-minimal' ]]; then + . "$HOME/.local/motd.sh" + # TODO - -- services + if [ -n "$SSH_CONNECTION" ]; then + # SSH + bash_motd --banner --processor --memory --diskspace --services --docker --updates --letsencrypt --login + elif command -v qubes-vmexec > /dev/null; then + # Qubes AppVM + bash_motd --banner --memory --diskspace --docker + elif command -v qubes-dom0-update > /dev/null; then + # Qubes dom0 + bash_motd --banner --updates + elif [ -d /Applications ] && [ -d /System ]; then + # macOS + bash_motd --banner + else + bash_motd --banner --processor --memory --diskspace --services --docker --updates --letsencrypt --login + fi fi fi fi fi -# Easy file sharing from the command line, using transfer.sh -transfer() { - if [ $# -eq 0 ]; then - echo -e "No arguments specified.\nUsage:\n transfer \n ... | transfer " >&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 -} - -# 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' -} - -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 -} - -# Run the quickstart script -quickstart() { - if command -v qvm-run >/dev/null; then - qvm-run --pass-io personal "curl -sSL https://install.doctor/qubes" >"$HOME/setup.sh" && bash "$HOME/setup.sh" - elif [ -d '/Applications' ] && [ -d '/Users' ] && [ -d '/Library' ]; then - curl -sSL https://install.doctor/quickstart >"$HOME/setup.sh" && bash "$HOME/setup.sh" - elif [ -f '/etc/os-release' ]; then - curl -sSL https://install.doctor/quickstart >"$HOME/setup.sh" && bash "$HOME/setup.sh" - fi - rm -f "$HOME/setup.sh" -} - -# 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 -} - -### Aliases - ### Colorize alias ls='ls --color=auto' alias grep='grep --color=auto' @@ -227,7 +125,7 @@ alias diff='diff --color=auto' alias ip='ip --color=auto' alias pacman='pacman --color=auto' -### Aliases +### Aliases (better defaults for simple commands) alias cp='cp -v' alias rm='rm -I' alias mv='mv -iv' @@ -249,7 +147,7 @@ command -v bat > /dev/null && \ alias bat='bat --theme=ansi' && \ alias cat='bat --pager=never' && \ alias less='bat' -# in debian the command is batcat +# In Debian the command is batcat command -v batcat > /dev/null && \ alias batcat='batcat --theme=ansi' && \ alias cat='batcat --pager=never' && \ @@ -264,122 +162,6 @@ command -v btm > /dev/null && alias top='btm $([ "$COLOR_SCHEME" = "light" ] && command -v bashtop > /dev/null && alias top='bashtop' command -v bpytop > /dev/null && alias top='bpytop' -# Create an Authelia password hash -alias autheliapassword='docker run authelia/authelia:latest authelia hash-password' - -# Shows IP addresses that are currently banned by fail2ban -alias banned='sudo zgrep "Ban" /var/log/fail2ban.log*' - -alias connections='nm-connection-editor' - -# Make copy command verbose -alias cp='cp -v' - -# Copies with a progress bar -alias cpv='rsync -ah --info=progress2' - -# Download a file -alias download='curl --continue-at - --location --progress-bar --remote-name --remote-time' - -# Download a website -alias downloadsite='wget --mirror -p --convert-links -P' - -# Flush DNS -alias flushdns='sudo systemd-resolve --flush-caches && sudo systemd-resolve --statistics' - -# FontBook for macOS -alias fontbook="open -b com.apple.FontBook" - -# Get the possible GRUB resolutions -alias grubresolutions='sudo hwinfo --framebuffer' - -# Execute git command with sudo priviledges while retaining .gitconfig -alias gsudo='sudo git -c "include.path="${XDG_CONFIG_DIR:-$HOME/.config}/git/config\" -c \"include.path=$HOME/.gitconfig\"' - -# Create hashed password for Ansible user creation -alias hashpassword='mkpasswd --method=sha-512' - -# Show full output when using ls -alias ls='ls -AlhF --color=auto' - -# Create parent directories automatically -alias mkdir='mkdir -pv' - -# Make mount command output readable -alias mount='mount | column -t' - -# Make mv command verbose -alias mv='mv -v' - -# Show IP address -alias myip='curl http://ipecho.net/plain; echo' - -# Shows local IP addresses -alias mylocalip="ifconfig | grep -Eo 'inet (addr:|adr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'" - -# Show open ports -alias ports='sudo netstat -tulanp' - -# Shuts down the computer, skipping the shutdown scripts -alias poweroff='sudo /sbin/poweroff' - -# Open the Rclone web GUI -alias rclonegui='rclone rcd --rc-web-gui --rc-user=admin --rc-pass=pass --rc-serve' - -# Reboot the computer -alias reboot='sudo /sbin/reboot' - -# Make rm command verbose -alias rm='rm -vi' - -# Launch the Python Simple HTTP Server -alias serve='python -m SimpleHTTPServer' - -# Generate a SHA1 digest -alias sha1='openssl sha1' - -# Shutdown the computer -alias shutdown='sudo /sbin/shutdown' - -# Speed test -alias speedtest='wget -O /dev/null http://speedtest.wdc01.softlayer.com/downloads/test10.zip' - -# Shortcut for config file -alias sshconfig='${EDITOR:code} ~/.ssh/config' - -# Pastebin -alias sprunge='curl -F "sprunge=<-" http://sprunge.us' - -# Disable Tor for current shell -alias toroff='source torsocks off' - -# Enable Tor for current shell -alias toron='source torsocks on' - -# Test Tor connection -alias tortest='curl --socks5-hostname 127.0.0.1:9050 --silent https://check.torproject.org/ | head -25' - -# Unban IP address (e.g. unban 10.14.24.14) -alias unban='sudo fail2ban-client set sshd unbanip' - -# Recursively encrypts files using Ansible Vault -alias unvaultdir='find . -type f -printf "%h/\"%f\" " | xargs ansible-vault decrypt' - -# Alias for updating software -alias update='sudo apt-get update && sudo apt-get upgrade' - -# Sets v as an alias for vim -alias v='vim' - -# Recursively encrypts files using Ansible Vault -alias vaultdir='find . -type f -printf "%h/\"%f\" " | xargs ansible-vault encrypt' - -# Shows nice looking report of weather -alias weather='curl -A curl wttr.in' - -# Change .wget-hsts file location -alias wget="wget --hsts-file ~/.config/.wget-hsts" - # vim as default export EDITOR="vim"