cswimr/home
Archived
Template
1
0
Fork 0

fixed aliases and added functions! this took so long lol

This commit is contained in:
Seaswimmer 2024-10-11 18:33:12 -04:00
parent b4d198ea69
commit 0f5e703cbe
Signed by: cswimr
GPG key ID: A9C162E867C851FA
2 changed files with 147 additions and 53 deletions

View file

@ -1,8 +1,8 @@
if [[ $+commands[pay-respects] ]]; then
if (( $+commands[pay-respects] )); then
alias f="$(pay-respects zsh)"
fi
if [[ $+commands[navi] ]]; then
if (( $+commands[navi] )); then
eval "$(navi widget zsh)"
alias wtf="navi"
alias help="navi"
@ -10,6 +10,7 @@ fi
alias rzsh="source ~/.zshrc && echo 'Successfully reloaded zsh!'"
alias aliases="${EDITOR} $ZSH_CUSTOM/aliases.zsh && rzsh"
alias func="${EDITOR} $ZSH_CUSTOM/func.zsh && rzsh"
alias zshrc="${EDITOR} ~/.zshrc && rzsh"
alias zshconfig="zshrc"
alias zshcustom="${EDITOR} $ZSH_CUSTOM && rzsh"
@ -18,76 +19,34 @@ alias vi="${EDITOR}"
alias vim="${EDITOR}"
alias nano="${EDITOR}"
if [[ $+commands[fastfetch] ]]; then
alias neofetch="fastfetch"
alias nf="fastfetch"
alias ff="fastfetch"
fi
if [[ $+commands[uwufetch] ]]; then
alias uf="uwufetch"
fi
if [[ $+commands[pacman] ]]; then
if (( $+commands[pacman] )); then
# this lists packages installed with pacman by size in mebibytes
alias pacsize="pacman -Qi | egrep '^(Name|Installed)' | cut -f2 -d':' | paste - - | column -t | sort -nrk 2 | grep MiB | less"
fi
if [[ $+commands[yay] ]]; then
if (( $+commands[yay] )); then
alias aur="yay"
alias yaystats="yay -P --stats"
alias pacstats="yaystats"
fi
if [[ $+commands[lazygit] ]]; then
if (( $+commands[lazygit] )); then
alias lg="lazygit"
fi
if [[ $+commands[lazydocker] ]]; then
if (( $+commands[lazydocker] )); then
alias lad="lazydocker"
fi
if [[ $+commands[btop] ]]; then
alias htop="btop"
fi
if [[ "${XDG_SESSION_TYPE}" == "x11" ]]; then
if [[ $+commands[xsel] ]]; then
alias clip="xsel -ib"
elif [[ $+commands[xclip] ]]; then
alias clip="xclip"
else
alias clip="Detected x11, but xsel or xclip are not installed."
fi
elif [[ -n "${WAYLAND_DISPLAY}" ]]; then
if [[ $+commands[wl-copy] ]]; then
alias clip="wl-copy"
else
alias clip="Detected Wayland, but wl-copy is not installed."
fi
elif [[ -n "${SSH_CONNECTION}" ]]; then
if [[ $+commands[lemonade] ]]; then
alias clip="lemonade copy"
else
alias clip="Detected an SSH connection, but lemonade is not installed."
fi
else
alias clip='echo "Cannot determine desktop session type, are you running a display server that is not X11 or Wayland?"'
fi
if [[ $+commands[nvidia-smi] ]]; then
if (( $+commands[nvidia-smi] )); then
alias driver="nvidia-smi"
fi
if [[ $+commands[nvidia-settings] ]]; then
if (( $+commands[nvidia-settings] )); then
alias gpu="sudo nvidia-settings"
fi
if [[ $+commands[forgejo-runner] ]]; then
alias runactions="forgejo-runner exec --network=host --default-actions-url=https://www.coastalcommits.com --gitea-instance=https://www.coastalcommits.com"
if (( $+commands[forgejo-runner] )); then
alias runactions="forgejo-runner exec --network=host --default-actions-url=https://www.coastalcommits.com --gitea-instance=https://www.coastalcommits.com"
fi
if [[ $+commands[tailscale] ]]; then
if (( $+commands[tailscale] )); then
alias taildrop="tailscale file"
fi
alias protontricks="flatpak run com.github.Matoking.protontricks"

135
.zshc/func.zsh Normal file
View file

@ -0,0 +1,135 @@
function clip {
if [[ $(uname) == "Darwin" ]];then
command pbcopy $@
elif (( "${XDG_SESSION_TYPE}" == "x11" )); then
if (( $+commands[xsel] )); then
command xsel -ib $@
elif (( $+commands[xclip] )); then
command xclip $@
else
echo "Detected X11, but xsel or xclip are not installed."
fi
elif (( -n {WAYLAND_DISPLAY} )); then
if (( $+commands[wl-copy] )); then
command wl-copy $@
else
echo "Detected Wayland, but wl-copy is not installed."
fi
elif (( -n {SSH_CONNECTION} )); then
if (( $+commands[lemonade] )); then
command lemonade copy $@
else
echo "Detected an SSH connection, but lemonade is not installed."
fi
else
echo "Cannot determine desktop session type, are you running a display server that is not X11 or Wayland?"
fi
}
function zipline {
# see spectacle-screenshot for example usage
readonly file=${1:?Please provide the path to the file you want to upload.}
readonly name=${2:?Please provide an application name to use in notify-send.}
readonly desktopentry=${3:?Please provide a path to a desktop entry file.}
readonly token=${ZIPLINE_TOKEN:?Environment variable ZIPLINE_TOKEN is not set. Please set it to your Zipline API token. I recommend placing it in a file at ~/.config/environment.d/zipline.conf}
readonly url=${ZIPLINE_URL:?Environment variable ZIPLINE_URL is not set. Please set it to the URL of your Zipline instance. I recommend placing it in a file at ~/.config/environment.d/zipline.conf}
temp_file=$(mktemp)
trap 'rm -f "$temp_file"' EXIT
if (( ! $+commands[jq] )); then
echo "jq is not installed."
return 1
fi
if (( ! $+commands[curl] )); then
echo "curl is not installed."
return 1
fi
if (( ! $+commands[notify-send] )); then
echo "notify-send is not installed."
return 1
fi
if [[ ! -f "${file}" ]]; then
echo "File does not exist."
return 1
fi
if ! does-desktop-entry-exist "$desktopentry"; then
echo "Desktop entry does not exist."
return 1
fi
if curl -sS -fH "authorization: $token" "${url%/}/api/upload" -F file="@$file" -H "Content-Type: multipart/form-data" >"$temp_file" 2>&1; then
readonly link=$(jq -r '.files[0]' <"$temp_file" | tr -d '\n')
echo -n "$link" | clip
echo "Upload successful. Link copied to clipboard: $link"
notify-send -a "$name" -u low -c transfer.complete -i "$file" -h "string:desktop-entry:$desktopentry" "Upload Successful" "Link copied to clipboard:\n$link"
else
echo "Upload failed. Error message: $(<"$temp_file")"
notify-send -a "$name" -u critical -c transfer.error -h "string:desktop-entry:$desktopentry" "Upload Failed" "$(<"$temp_file")"
return 1
fi
}
function spectacle-screenshot {
# takes one argument, the path to save the screenshot to - if not provided, a temp file will be used
if (( ! $+commands[spectacle] )); then
echo "spectacle is not installed."
return 1
fi
if [[ -z "${1}" ]]; then
readonly file=$(mktemp /tmp/spectacle-screenshot.XXXXXXXX.png)
else
readonly file=$1
fi
spectacle --nonotify --background --region --copy-image --output "$file"
[ ! -s "$file" ] && exit 1
trap 'rm -f "$file"' EXIT
zipline "$file" Spectacle org.kde.spectacle.desktop
}
function does-desktop-entry-exist {
readonly desktopentry=${1:?Please provide the full filename of the desktop entry.}
local entrypaths=(
"/usr/share/applications"
"/usr/local/share/applications"
"$HOME/.local/share/applications"
)
for entrypath in "${entrypaths[@]}"; do
if [[ -f "$entrypath/$desktopentry" ]]; then
return 0
fi
done
echo "Desktop entry $desktopentry does not exist."
return 1
}
function htop btop {
if (( $+commands[btop] )); then
command btop $@
else
command htop $@
fi
}
function fastfetch ff neofetch nf {
if (( $+commands[fastfetch] )); then
command fastfetch $@
elif (( $+commands[neofetch] )); then
echo "Warning: fastfetch is not installed, falling back to neofetch."
command neofetch $@
else
echo "Warning: fastfetch and neofetch are not installed, cannot fetch system information."
fi
}