added all the dotfiles

This commit is contained in:
liph
2025-12-19 22:53:46 +00:00
parent e29ca99666
commit 303cd3b5a9
61 changed files with 3148 additions and 0 deletions

32
scripts/scripts/borg-backup.sh Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/bash
SOURCE_DIRS=("/home/liph/Documents" "/home/liph/Pictures" "/home/liph/Downloads")
REPO_DIR="/home/liph/borg-repo"
BORG_PASSPHRASE="1ChagearC"
export BORG_PASSPHRASE
for SOURCE_DIR in "${SOURCE_DIRS[@]}"; do
ARCHIVE_NAME="{hostname}-{user}-{now}"
echo "Starting backup of ${SOURCE_DIR}..."
borg create --stats --progress \
"${REPO_DIR}::${ARCHIVE_NAME}" \
"${SOURCE_DIR}"
if [ $? -eq 0 ]; then
echo "Backup of ${SOURCE_DIR} completed successfully!"
else
echo "Backup of ${SOURCE_DIR} failed!"
fi
done
echo "Pruning old backups..."
borg prune --stats --progress \
--keep-daily=7 \
--keep-weekly=4 \
--keep-monthly=6 \
"${REPO_DIR}"
echo "Backup and pruning completed!"

95
scripts/scripts/borg-mac.sh Executable file
View File

@@ -0,0 +1,95 @@
#!/bin/sh
# Setting this, so the repo does not need to be given on the commandline:
# export BORG_REPO=ssh://username@example.com:2022/~/backup/main
#export BORG_REPO=~/backup/
# See the section "Passphrase notes" for more infos.
#export BORG_PASSPHRASE='1ChagearC'
export BORG_REPO="ssh://100.121.203.110:2222/./repo/borg-repo"
export BORG_PASSPHRASE="1ChagearC" # Encryption key
BACKUP_SOURCES=(
"/home/liph/Downloads/"
"/home/liph/dotfiles/"
"/home/liph/scripts"
) # What to back up
BACKUP_NAME="laptop-$(date +%Y-%m-%d)" # Dynamic backup name
# some helpers and error handling:
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
info "Starting backup"
# Initialize Borg repo (if not exists)
borg init --encryption=repokey "$BORG_REPO" 2>/dev/null || true
# Backup the most important directories into an archive named after
# the machine this script is currently running on:
borg create \
--verbose \
--filter AME \
--list \
--stats \
--show-rc \
--progress \
--compression lz4 \
--exclude-caches \
--exclude 'home/*/.cache/*' \
--exclude 'var/tmp/*' \
"$BORG_REPO::$BACKUP_NAME" \
"${BACKUP_SOURCES[@]}" \
# ::'{hostname}-{user}-{now}' \
# /home/liph/Documents/ \
# /home/liph/Pictures/ \
# /home/liph/Downloads/
# /etc \
# /home \
# /root \
# /var
backup_exit=$?
info "Pruning repository"
# Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
# archives of THIS machine. The '{hostname}-*' matching is very important to
# limit prune's operation to this machine's archives and not apply to
# other machines' archives also:
borg prune \
--list \
--glob-archives '{hostname}-*' \
--show-rc \
--keep-daily 7 \
--keep-weekly 4 \
--keep-monthly 6
"$BORG_REPO"
prune_exit=$?
# actually free repo disk space by compacting segments
info "Compacting repository"
borg compact
compact_exit=$?
# use highest exit code as global exit code
global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
global_exit=$(( compact_exit > global_exit ? compact_exit : global_exit ))
if [ ${global_exit} -eq 0 ]; then
info "Backup, Prune, and Compact finished successfully"
elif [ ${global_exit} -eq 1 ]; then
info "Backup, Prune, and/or Compact finished with warnings"
else
info "Backup, Prune, and/or Compact finished with errors"
fi
exit ${global_exit}
# Check backup integrity
borg check "$BORG_REPO"

95
scripts/scripts/borg-server.sh Executable file
View File

@@ -0,0 +1,95 @@
#!/bin/sh
# Setting this, so the repo does not need to be given on the commandline:
# export BORG_REPO=ssh://username@example.com:2022/~/backup/main
#export BORG_REPO=~/backup/
# See the section "Passphrase notes" for more infos.
#export BORG_PASSPHRASE='1ChagearC'
export BORG_REPO="ssh://100.121.203.110:2222/./repo/borg-repo"
export BORG_PASSPHRASE="1ChagearC" # Encryption key
BACKUP_SOURCES=(
"/home/liph/Documents"
"/home/liph/Pictures"
"/home/liph/scripts"
) # What to back up
BACKUP_NAME="server-$(date +%Y-%m-%d)" # Dynamic backup name
# some helpers and error handling:
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
info "Starting backup"
# Initialize Borg repo (if not exists)
borg init --encryption=repokey "$BORG_REPO" 2>/dev/null || true
# Backup the most important directories into an archive named after
# the machine this script is currently running on:
borg create \
--verbose \
--filter AME \
--list \
--stats \
--show-rc \
--progress \
--compression lz4 \
--exclude-caches \
--exclude 'home/*/.cache/*' \
--exclude 'var/tmp/*' \
"$BORG_REPO::$BACKUP_NAME" \
"${BACKUP_SOURCES[@]}" \
# ::'{hostname}-{user}-{now}' \
# /home/liph/Documents/ \
# /home/liph/Pictures/ \
# /home/liph/Downloads/
# /etc \
# /home \
# /root \
# /var
backup_exit=$?
info "Pruning repository"
# Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
# archives of THIS machine. The '{hostname}-*' matching is very important to
# limit prune's operation to this machine's archives and not apply to
# other machines' archives also:
borg prune \
--list \
--glob-archives '{hostname}-*' \
--show-rc \
--keep-daily 7 \
--keep-weekly 4 \
--keep-monthly 6
"$BORG_REPO"
prune_exit=$?
# actually free repo disk space by compacting segments
info "Compacting repository"
borg compact
compact_exit=$?
# use highest exit code as global exit code
global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
global_exit=$(( compact_exit > global_exit ? compact_exit : global_exit ))
if [ ${global_exit} -eq 0 ]; then
info "Backup, Prune, and Compact finished successfully"
elif [ ${global_exit} -eq 1 ]; then
info "Backup, Prune, and/or Compact finished with warnings"
else
info "Backup, Prune, and/or Compact finished with errors"
fi
exit ${global_exit}
# Check backup integrity
borg check "$BORG_REPO"

95
scripts/scripts/borg.sh Executable file
View File

@@ -0,0 +1,95 @@
#!/bin/sh
# Setting this, so the repo does not need to be given on the commandline:
# export BORG_REPO=ssh://username@example.com:2022/~/backup/main
#export BORG_REPO=~/backup/
# See the section "Passphrase notes" for more infos.
#export BORG_PASSPHRASE='1ChagearC'
export BORG_REPO="ssh://100.121.203.110:2222/./repo/borg-repo"
export BORG_PASSPHRASE="1ChagearC" # Encryption key
BACKUP_SOURCES=(
"/home/liph/Documents"
"/home/liph/Pictures"
"/home/liph/scripts"
) # What to back up
BACKUP_NAME="laptop-$(date +%Y-%m-%d)" # Dynamic backup name
# some helpers and error handling:
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
info "Starting backup"
# Initialize Borg repo (if not exists)
borg init --encryption=repokey "$BORG_REPO" 2>/dev/null || true
# Backup the most important directories into an archive named after
# the machine this script is currently running on:
borg create \
--verbose \
--filter AME \
--list \
--stats \
--show-rc \
--progress \
--compression lz4 \
--exclude-caches \
--exclude 'home/*/.cache/*' \
--exclude 'var/tmp/*' \
"$BORG_REPO::$BACKUP_NAME" \
"${BACKUP_SOURCES[@]}" \
# ::'{hostname}-{user}-{now}' \
# /home/liph/Documents/ \
# /home/liph/Pictures/ \
# /home/liph/Downloads/
# /etc \
# /home \
# /root \
# /var
backup_exit=$?
info "Pruning repository"
# Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
# archives of THIS machine. The '{hostname}-*' matching is very important to
# limit prune's operation to this machine's archives and not apply to
# other machines' archives also:
borg prune \
--list \
--glob-archives '{hostname}-*' \
--show-rc \
--keep-daily 7 \
--keep-weekly 4 \
--keep-monthly 6
"$BORG_REPO"
prune_exit=$?
# actually free repo disk space by compacting segments
info "Compacting repository"
borg compact
compact_exit=$?
# use highest exit code as global exit code
global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
global_exit=$(( compact_exit > global_exit ? compact_exit : global_exit ))
if [ ${global_exit} -eq 0 ]; then
info "Backup, Prune, and Compact finished successfully"
elif [ ${global_exit} -eq 1 ]; then
info "Backup, Prune, and/or Compact finished with warnings"
else
info "Backup, Prune, and/or Compact finished with errors"
fi
exit ${global_exit}
# Check backup integrity
borg check "$BORG_REPO"

310
scripts/scripts/fzf-git.sh Executable file
View File

@@ -0,0 +1,310 @@
# Fzf with Git in the shell
# You can find this whole script from Junegunn Github repo below
# https://github.com/junegunn/fzf-git.sh
# Script is used in .zshrc
# shellcheck disable=SC2039
[[ $0 = - ]] && return
__fzf_git_color() {
if [[ -n $NO_COLOR ]]; then
echo never
elif [[ $# -gt 0 ]] && [[ -n $FZF_GIT_PREVIEW_COLOR ]]; then
echo "$FZF_GIT_PREVIEW_COLOR"
else
echo "${FZF_GIT_COLOR:-always}"
fi
}
__fzf_git_cat() {
if [[ -n $FZF_GIT_CAT ]]; then
echo "$FZF_GIT_CAT"
return
fi
# Sometimes bat is installed as batcat
_fzf_git_bat_options="--style='${BAT_STYLE:-full}' --color=$(__fzf_git_color .) --pager=never"
if command -v batcat > /dev/null; then
echo "batcat $_fzf_git_bat_options"
elif command -v bat > /dev/null; then
echo "bat $_fzf_git_bat_options"
else
echo cat
fi
}
if [[ $# -eq 1 ]]; then
branches() {
git branch "$@" --sort=-committerdate --sort=-HEAD --format=$'%(HEAD) %(color:yellow)%(refname:short) %(color:green)(%(committerdate:relative))\t%(color:blue)%(subject)%(color:reset)' --color=$(__fzf_git_color) | column -ts$'\t'
}
refs() {
git for-each-ref --sort=-creatordate --sort=-HEAD --color=$(__fzf_git_color) --format=$'%(refname) %(color:green)(%(creatordate:relative))\t%(color:blue)%(subject)%(color:reset)' |
eval "$1" |
sed 's#^refs/remotes/#\x1b[95mremote-branch\t\x1b[33m#; s#^refs/heads/#\x1b[92mbranch\t\x1b[33m#; s#^refs/tags/#\x1b[96mtag\t\x1b[33m#; s#refs/stash#\x1b[91mstash\t\x1b[33mrefs/stash#' |
column -ts$'\t'
}
hashes() {
git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --graph --color=$(__fzf_git_color) "$@"
}
case "$1" in
branches)
echo $'CTRL-O (open in browser) ALT-A (show all branches)\n'
branches
;;
all-branches)
echo $'CTRL-O (open in browser)\n'
branches -a
;;
hashes)
echo $'CTRL-O (open in browser) CTRL-D (diff)\nCTRL-S (toggle sort) ALT-A (show all hashes)\n'
hashes
;;
all-hashes)
echo $'CTRL-O (open in browser) CTRL-D (diff)\nCTRL-S (toggle sort)\n'
hashes --all
;;
refs)
echo $'CTRL-O (open in browser) ALT-E (examine in editor) ALT-A (show all refs)\n'
refs 'grep -v ^refs/remotes'
;;
all-refs)
echo $'CTRL-O (open in browser) ALT-E (examine in editor)\n'
refs 'cat'
;;
nobeep) ;;
*) exit 1 ;;
esac
elif [[ $# -gt 1 ]]; then
set -e
branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
if [[ $branch = HEAD ]]; then
branch=$(git describe --exact-match --tags 2> /dev/null || git rev-parse --short HEAD)
fi
# Only supports GitHub for now
case "$1" in
commit)
hash=$(grep -o "[a-f0-9]\{7,\}" <<< "$2")
path=/commit/$hash
;;
branch|remote-branch)
branch=$(sed 's/^[* ]*//' <<< "$2" | cut -d' ' -f1)
remote=$(git config branch."${branch}".remote || echo 'origin')
branch=${branch#$remote/}
path=/tree/$branch
;;
remote)
remote=$2
path=/tree/$branch
;;
file) path=/blob/$branch/$(git rev-parse --show-prefix)$2 ;;
tag) path=/releases/tag/$2 ;;
*) exit 1 ;;
esac
remote=${remote:-$(git config branch."${branch}".remote || echo 'origin')}
remote_url=$(git remote get-url "$remote" 2> /dev/null || echo "$remote")
if [[ $remote_url =~ ^git@ ]]; then
url=${remote_url%.git}
url=${url#git@}
url=https://${url/://}
elif [[ $remote_url =~ ^http ]]; then
url=${remote_url%.git}
fi
case "$(uname -s)" in
Darwin) open "$url$path" ;;
*) xdg-open "$url$path" ;;
esac
exit 0
fi
if [[ $- =~ i ]]; then
# -----------------------------------------------------------------------------
# Redefine this function to change the options
_fzf_git_fzf() {
fzf-tmux -p80%,60% -- \
--layout=reverse --multi --height=50% --min-height=20 --border \
--border-label-pos=2 \
--color='header:italic:underline,label:blue' \
--preview-window='right,50%,border-left' \
--bind='ctrl-/:change-preview-window(down,50%,border-top|hidden|)' "$@"
}
_fzf_git_check() {
git rev-parse HEAD > /dev/null 2>&1 && return
[[ -n $TMUX ]] && tmux display-message "Not in a git repository"
return 1
}
__fzf_git=${BASH_SOURCE[0]:-${(%):-%x}}
__fzf_git=$(readlink -f "$__fzf_git" 2> /dev/null || /usr/bin/ruby --disable-gems -e 'puts File.expand_path(ARGV.first)' "$__fzf_git" 2> /dev/null)
_fzf_git_files() {
_fzf_git_check || return
local root query
root=$(git rev-parse --show-toplevel)
[[ $root != "$PWD" ]] && query='!../ '
(git -c color.status=$(__fzf_git_color) status --short --no-branch
git ls-files "$root" | grep -vxFf <(git status -s | grep '^[^?]' | cut -c4-; echo :) | sed 's/^/ /') |
_fzf_git_fzf -m --ansi --nth 2..,.. \
--border-label '📁 Files' \
--header $'CTRL-O (open in browser) ALT-E (open in editor)\n\n' \
--bind "ctrl-o:execute-silent:bash $__fzf_git file {-1}" \
--bind "alt-e:execute:${EDITOR:-vim} {-1} > /dev/tty" \
--query "$query" \
--preview "git diff --no-ext-diff --color=$(__fzf_git_color .) -- {-1} | sed 1,4d; $(__fzf_git_cat) {-1}" "$@" |
cut -c4- | sed 's/.* -> //'
}
_fzf_git_branches() {
_fzf_git_check || return
bash "$__fzf_git" branches |
_fzf_git_fzf --ansi \
--border-label '🌲 Branches' \
--header-lines 2 \
--tiebreak begin \
--preview-window down,border-top,40% \
--color hl:underline,hl+:underline \
--no-hscroll \
--bind 'ctrl-/:change-preview-window(down,70%|hidden|)' \
--bind "ctrl-o:execute-silent:bash $__fzf_git branch {}" \
--bind "alt-a:change-border-label(🌳 All branches)+reload:bash \"$__fzf_git\" all-branches" \
--preview "git log --oneline --graph --date=short --color=$(__fzf_git_color .) --pretty='format:%C(auto)%cd %h%d %s' \$(sed s/^..// <<< {} | cut -d' ' -f1) --" "$@" |
sed 's/^..//' | cut -d' ' -f1
}
_fzf_git_tags() {
_fzf_git_check || return
git tag --sort -version:refname |
_fzf_git_fzf --preview-window right,70% \
--border-label '📛 Tags' \
--header $'CTRL-O (open in browser)\n\n' \
--bind "ctrl-o:execute-silent:bash $__fzf_git tag {}" \
--preview "git show --color=$(__fzf_git_color .) {}" "$@"
}
_fzf_git_hashes() {
_fzf_git_check || return
bash "$__fzf_git" hashes |
_fzf_git_fzf --ansi --no-sort --bind 'ctrl-s:toggle-sort' \
--border-label '🍡 Hashes' \
--header-lines 3 \
--bind "ctrl-o:execute-silent:bash $__fzf_git commit {}" \
--bind "ctrl-d:execute:grep -o '[a-f0-9]\{7,\}' <<< {} | head -n 1 | xargs git diff --color=$(__fzf_git_color) > /dev/tty" \
--bind "alt-a:change-border-label(🍇 All hashes)+reload:bash \"$__fzf_git\" all-hashes" \
--color hl:underline,hl+:underline \
--preview "grep -o '[a-f0-9]\{7,\}' <<< {} | head -n 1 | xargs git show --color=$(__fzf_git_color .)" "$@" |
awk 'match($0, /[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]*/) { print substr($0, RSTART, RLENGTH) }'
}
_fzf_git_remotes() {
_fzf_git_check || return
git remote -v | awk '{print $1 "\t" $2}' | uniq |
_fzf_git_fzf --tac \
--border-label '📡 Remotes' \
--header $'CTRL-O (open in browser)\n\n' \
--bind "ctrl-o:execute-silent:bash $__fzf_git remote {1}" \
--preview-window right,70% \
--preview "git log --oneline --graph --date=short --color=$(__fzf_git_color .) --pretty='format:%C(auto)%cd %h%d %s' '{1}/$(git rev-parse --abbrev-ref HEAD)' --" "$@" |
cut -d$'\t' -f1
}
_fzf_git_stashes() {
_fzf_git_check || return
git stash list | _fzf_git_fzf \
--border-label '🥡 Stashes' \
--header $'CTRL-X (drop stash)\n\n' \
--bind 'ctrl-x:reload(git stash drop -q {1}; git stash list)' \
-d: --preview "git show --color=$(__fzf_git_color .) {1}" "$@" |
cut -d: -f1
}
_fzf_git_lreflogs() {
_fzf_git_check || return
git reflog --color=$(__fzf_git_color) --format="%C(blue)%gD %C(yellow)%h%C(auto)%d %gs" | _fzf_git_fzf --ansi \
--border-label '📒 Reflogs' \
--preview "git show --color=$(__fzf_git_color .) {1}" "$@" |
awk '{print $1}'
}
_fzf_git_each_ref() {
_fzf_git_check || return
bash "$__fzf_git" refs | _fzf_git_fzf --ansi \
--nth 2,2.. \
--tiebreak begin \
--border-label '☘️ Each ref' \
--header-lines 2 \
--preview-window down,border-top,40% \
--color hl:underline,hl+:underline \
--no-hscroll \
--bind 'ctrl-/:change-preview-window(down,70%|hidden|)' \
--bind "ctrl-o:execute-silent:bash $__fzf_git {1} {2}" \
--bind "alt-e:execute:${EDITOR:-vim} <(git show {2}) > /dev/tty" \
--bind "alt-a:change-border-label(🍀 Every ref)+reload:bash \"$__fzf_git\" all-refs" \
--preview "git log --oneline --graph --date=short --color=$(__fzf_git_color .) --pretty='format:%C(auto)%cd %h%d %s' {2} --" "$@" |
awk '{print $2}'
}
_fzf_git_worktrees() {
_fzf_git_check || return
git worktree list | _fzf_git_fzf \
--border-label '🌴 Worktrees' \
--header $'CTRL-X (remove worktree)\n\n' \
--bind 'ctrl-x:reload(git worktree remove {1} > /dev/null; git worktree list)' \
--preview "
git -c color.status=$(__fzf_git_color .) -C {1} status --short --branch
echo
git log --oneline --graph --date=short --color=$(__fzf_git_color .) --pretty='format:%C(auto)%cd %h%d %s' {2} --
" "$@" |
awk '{print $1}'
}
if [[ -n "${BASH_VERSION:-}" ]]; then
__fzf_git_init() {
bind -m emacs-standard '"\er": redraw-current-line'
bind -m emacs-standard '"\C-z": vi-editing-mode'
bind -m vi-command '"\C-z": emacs-editing-mode'
bind -m vi-insert '"\C-z": emacs-editing-mode'
local o c
for o in "$@"; do
c=${o:0:1}
bind -m emacs-standard '"\C-g\C-'$c'": " \C-u \C-a\C-k`_fzf_git_'$o'`\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er \C-h"'
bind -m vi-command '"\C-g\C-'$c'": "\C-z\C-g\C-'$c'\C-z"'
bind -m vi-insert '"\C-g\C-'$c'": "\C-z\C-g\C-'$c'\C-z"'
bind -m emacs-standard '"\C-g'$c'": " \C-u \C-a\C-k`_fzf_git_'$o'`\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er \C-h"'
bind -m vi-command '"\C-g'$c'": "\C-z\C-g'$c'\C-z"'
bind -m vi-insert '"\C-g'$c'": "\C-z\C-g'$c'\C-z"'
done
}
elif [[ -n "${ZSH_VERSION:-}" ]]; then
__fzf_git_join() {
local item
while read item; do
echo -n "${(q)item} "
done
}
__fzf_git_init() {
local m o
for o in "$@"; do
eval "fzf-git-$o-widget() { local result=\$(_fzf_git_$o | __fzf_git_join); zle reset-prompt; LBUFFER+=\$result }"
eval "zle -N fzf-git-$o-widget"
for m in emacs vicmd viins; do
eval "bindkey -M $m '^g^${o[1]}' fzf-git-$o-widget"
eval "bindkey -M $m '^g${o[1]}' fzf-git-$o-widget"
done
done
}
fi
__fzf_git_init files branches tags remotes hashes stashes lreflogs each_ref worktrees
# -----------------------------------------------------------------------------
fi

View File

@@ -0,0 +1,29 @@
#!/bin/bash
# Script to list recent files and open nvim using fzf
# set to an alias nlof in .zshrc
list_oldfiles() {
# Get the oldfiles list from Neovim
local oldfiles=($(nvim -u NONE --headless +'lua io.write(table.concat(vim.v.oldfiles, "\n") .. "\n")' +qa))
# Filter invalid paths or files not found
local valid_files=()
for file in "${oldfiles[@]}"; do
if [[ -f "$file" ]]; then
valid_files+=("$file")
fi
done
# Use fzf to select from valid files
local files=($(printf "%s\n" "${valid_files[@]}" | \
grep -v '\[.*' | \
fzf --multi \
--preview 'bat -n --color=always --line-range=:500 {} 2>/dev/null || echo "Error previewing file"' \
--height=70% \
--layout=default))
# Open selected files in Neovim
[[ ${#files[@]} -gt 0 ]] && nvim "${files[@]}"
}
# Call the function
list_oldfiles "$@"

2
scripts/scripts/hydroxide.sh Executable file
View File

@@ -0,0 +1,2 @@
hydroxide imap &
hydroxide smtp &

89
scripts/scripts/protonport.sh Executable file
View File

@@ -0,0 +1,89 @@
#!/bin/bash
# Configuration variables - change this for your setup
gluetun_container_name="gluetun"
qbittorrent_container_name="qbittorrent"
gluetun_origin="http://100.120.152.94:8888"
qb_origin="http://100.120.152.94:8099"
####################################################################
# Arrays for URLs
declare -A gluetun_urls=(
["pub_ip"]="$gluetun_origin/v1/publicip/ip"
["portforwarded"]="$gluetun_origin/v1/openvpn/portforwarded"
)
declare -A qbittorrent_urls=(
#used for getting and setting listen_port
["prefs"]="$qb_origin/api/v2/app/preferences"
["setPrefs"]="$qb_origin/api/v2/app/setPreferences"
)
# Function to check if a Docker container is running
is_container_running() {
local container_name="$1"
docker inspect -f '{{.State.Running}}' "$container_name" 2>/dev/null
# echo "Container $container_name status: $status"
}
get_vpn_external_ip() {
local url="$1"
curl -s "$url" | -r .'public_ip'
}
# Function to send a GET request and extract the port from the response
get_port_from_url() {
local url="$1"
local port_key
# Try 'port' key first
port_key=$(curl -s "$url" | jq -r '.port')
if [ "$port_key" == "null" ]; then
# If 'port' key is null, try 'listen_port' key
port_key=$(curl -s "$url" | jq -r '.listen_port')
fi
echo "$port_key"
}
# Function to send a POST request with JSON data
send_post_request() {
local url="$1"
local port="$2"
curl -s -X POST -d json={\"listen_port\":$port} "$url"
}
# Outputs container names
echo "Gluetun container name: $gluetun_container_name - Gluetun Origin URL: $gluetun_origin"
echo "qBittorrent container name: $qbittorrent_container_name - qBittorrent Origin URL: $qb_origin"
# Check if both containers are running
if [[ $(is_container_running "$gluetun_container_name") == $(is_container_running "$qbittorrent_container_name") ]]; then
echo "Both Gluetun and qBittorrent containers are running. Continuing."
external_ip=$(get_vpn_external_ip "${gluetun_urls["pub_ip"]}")
if [ -z "$external_ip" ]; then
echo "External IP is empty. Exiting script due to potential VPN or internet connection issue."
exit 1
else
echo "External IP is $external_ip therefore VPN is up"
fi
gluetun_port=$(get_port_from_url "${gluetun_urls["portforwarded"]}")
qbittorrent_port=$(get_port_from_url "${qbittorrent_urls["prefs"]}")
echo "Gluetun forwarded port is $gluetun_port"
echo "qBittorrent listen port is $qbittorrent_port"
if [ "$gluetun_port" -eq "$qbittorrent_port" ]; then
echo "qBittorrent listen port is already set to $qbittorrent_port. No need to change. Exiting script."
else
echo "Updating qBittorrent listen port to Gluetun forwarded port $gluetun_port."
send_post_request "${qbittorrent_urls["setPrefs"]}" "$gluetun_port"
qbittorrent_port=$(get_port_from_url "${qbittorrent_urls["prefs"]}")
echo "qBittorrent listen port updated to $qbittorrent_port. Exiting script."
fi
else
echo "Either Gluetun or qBittorrent container is not running. Exiting script."
fi

View File

@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# Save this file as ~/scripts/tmux-sessionizer
# Make it executable with: chmod +x ~/.local/bin/tmux-sessionizer
if [[ $# -eq 1 ]]; then
selected=$1
else
selected=$(fd -H . ~/dotfiles ~/Desktop/main-cs ~/Desktop/main-cs/Projects ~/ ~/Desktop/work ~/Desktop/work/youtube -t d -d 1 | fzf)
fi
if [[ -z $selected ]]; then
exit 0
fi
selected_name=$(basename "$selected" | tr . _)
tmux_running=$(pgrep tmux)
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
tmux new-session -s $selected_name -c $selected
exit 0
fi
if ! tmux has-session -t=$selected_name 2> /dev/null; then
tmux new-session -ds $selected_name -c $selected
fi
tmux switch-client -t $selected_name

View File

@@ -0,0 +1,33 @@
#!/bin/bash
# Script to find every single file and opens in neovim
# alias set as nzo in .zshrc
search_with_zoxdie() {
if [ -z "$1" ]; then
# use fd with fzf to select & open a file when no arg are provided
file="$(fd --type f -I -H -E .git -E .git-crypt -E .cache -E .backup | fzf --height=70% --preview='bat -n --color=always --line-range :500 {}')"
if [ -n "$file" ]; then
nvim "$file"
fi
else
# Handle when an arg is provided
lines=$(zoxide query -l | xargs -I {} fd --type f -I -H -E .git -E .git-crypt -E .cache -E .backup -E .vscode "$1" {} | fzf --no-sort) # Initial filter attempt with fzf
line_count="$(echo "$lines" | wc -l | xargs)" # Trim any leading spaces
if [ -n "$lines" ] && [ "$line_count" -eq 1 ]; then
# looks for the exact ones and opens it
file="$lines"
nvim "$file"
elif [ -n "$lines" ]; then
# If multiple files are found, allow further selection using fzf and bat for preview
file=$(echo "$lines" | fzf --query="$1" --height=70% --preview='bat -n --color=always --line-range :500 {}')
if [ -n "$file" ]; then
nvim "$file"
fi
else
echo "No matches found." >&2
fi
fi
}
search_with_zoxdie "$@"