diff --git a/bluelight.sh b/bluelight.sh new file mode 100755 index 0000000..6341a3d --- /dev/null +++ b/bluelight.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +SHADER_DIR="$HOME/.config/hypr/shaders" +SHADER_FILE="$SHADER_DIR/brightness.frag" + +# Ensure shader directory exists +mkdir -p "$SHADER_DIR" + +# Get screen brightness level +echo "Enter screen brightness level (0-10, where 10 = 100%):" +read -r LEVEL + +# Validate input +if ! [[ "$LEVEL" =~ ^[0-9]+$ ]] || [ "$LEVEL" -lt 0 ] || [ "$LEVEL" -gt 10 ]; then + echo "Invalid input. Please enter a number between 0 and 10." + exit 1 +fi + +# Convert to decimal (0-10 -> 0.0-1.0) +BRIGHTNESS=$(echo "scale=2; $LEVEL / 10" | bc) + +# Ask about keyboard backlight +echo "Adjust keyboard backlight? (y/n):" +read -r KBD_ADJUST + +if [[ "$KBD_ADJUST" == "y" || "$KBD_ADJUST" == "Y" ]]; then + echo "Enter keyboard backlight level (0-10, where 10 = 100%):" + read -r KBD_LEVEL + + # Validate keyboard input + if ! [[ "$KBD_LEVEL" =~ ^[0-9]+$ ]] || [ "$KBD_LEVEL" -lt 0 ] || [ "$KBD_LEVEL" -gt 10 ]; then + echo "Invalid input. Please enter a number between 0 and 10." + exit 1 + fi + + # Convert to percentage (0-10 -> 0-100) + KBD_PERCENT=$((KBD_LEVEL * 10)) + + # Set keyboard backlight + kbdlight set $KBD_PERCENT + echo "Keyboard backlight set to ${KBD_PERCENT}%" +fi + +# Ask about blue light filter +echo "Apply blue light filter? (y/n):" +read -r BLUELIGHT + +# Create shader based on choice +cat > "$SHADER_FILE" << EOF +#version 300 es + +precision mediump float; + +in vec2 v_texcoord; +out vec4 fragColor; +uniform sampler2D tex; + +void main() { + vec4 pixColor = texture(tex, v_texcoord); + +EOF + +if [[ "$BLUELIGHT" == "y" || "$BLUELIGHT" == "Y" ]]; then + cat >> "$SHADER_FILE" << EOF + // Reduce blue light + pixColor.r *= 1.0; + pixColor.g *= 0.85; + pixColor.b *= 0.65; + +EOF +fi + +cat >> "$SHADER_FILE" << EOF + // Adjust brightness + pixColor.rgb *= $BRIGHTNESS; + + fragColor = pixColor; +} +EOF + +# Apply shader +if [ -z "$HYPRLAND_INSTANCE_SIGNATURE" ]; then + export HYPRLAND_INSTANCE_SIGNATURE=$(ls -t /tmp/hypr/ 2>/dev/null | head -n1) +fi +/usr/bin/hyprctl keyword decoration:screen_shader "$SHADER_FILE" + +echo "Screen brightness set to ${LEVEL}0% $([ "$BLUELIGHT" == "y" ] || [ "$BLUELIGHT" == "Y" ] && echo "with blue light filter")" diff --git a/borg-backup.sh b/borg-backup.sh new file mode 100755 index 0000000..5f7f4d5 --- /dev/null +++ b/borg-backup.sh @@ -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!" + diff --git a/borg-mac.sh b/borg-mac.sh new file mode 100755 index 0000000..5175778 --- /dev/null +++ b/borg-mac.sh @@ -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" diff --git a/borg-server.sh b/borg-server.sh new file mode 100644 index 0000000..7b623ff --- /dev/null +++ b/borg-server.sh @@ -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" diff --git a/borg.sh b/borg.sh new file mode 100755 index 0000000..b6ea062 --- /dev/null +++ b/borg.sh @@ -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" diff --git a/br_blue.sh b/br_blue.sh new file mode 100755 index 0000000..4f42411 --- /dev/null +++ b/br_blue.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# Path to the brightness shader file +SHADER_DIR="$HOME/.config/hypr/shaders" +SHADER_FILE="$SHADER_DIR/brightness.frag" + +# Ensure shader directory exists +mkdir -p "$SHADER_DIR" + +# Check if shader file exists, if not create with default values +if [ ! -f "$SHADER_FILE" ]; then + CURRENT_BRIGHTNESS=1.0 + BLUELIGHT_ENABLED=false +else + # Get current brightness multiplier + CURRENT_BRIGHTNESS=$(grep -oP 'pixColor.rgb \*= \K[0-9.]+' "$SHADER_FILE" | tail -1) + + # Check current state by looking at the blue channel multiplier + if grep -q "pixColor.b \*= 0.6" "$SHADER_FILE"; then + BLUELIGHT_ENABLED=true + else + BLUELIGHT_ENABLED=false + fi +fi + +# Toggle the blue light filter state +if [ "$BLUELIGHT_ENABLED" = true ]; then + # Filter is ON, turn it OFF + NEW_STATE=false + echo "Blue light filter: OFF" +else + # Filter is OFF, turn it ON + NEW_STATE=true + echo "Blue light filter: ON" +fi + +# Recreate the shader file +cat > "$SHADER_FILE" << EOF +#version 300 es + +precision mediump float; + +in vec2 v_texcoord; +out vec4 fragColor; +uniform sampler2D tex; + +void main() { + vec4 pixColor = texture(tex, v_texcoord); + +EOF + +if [ "$NEW_STATE" = true ]; then + cat >> "$SHADER_FILE" << EOF + // Reduce blue light + pixColor.r *= 1.0; + pixColor.g *= 0.85; + pixColor.b *= 0.6; + +EOF +fi + +cat >> "$SHADER_FILE" << EOF + // Adjust brightness + pixColor.rgb *= $CURRENT_BRIGHTNESS; + + fragColor = pixColor; +} +EOF + +# Apply shader +if [ -z "$HYPRLAND_INSTANCE_SIGNATURE" ]; then + export HYPRLAND_INSTANCE_SIGNATURE=$(ls -t /tmp/hypr/ 2>/dev/null | head -n1) +fi +/usr/bin/hyprctl keyword decoration:screen_shader "$SHADER_FILE" diff --git a/br_down.sh b/br_down.sh new file mode 100755 index 0000000..19de79a --- /dev/null +++ b/br_down.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# Path to the brightness shader file +SHADER_DIR="$HOME/.config/hypr/shaders" +SHADER_FILE="$SHADER_DIR/brightness.frag" + +# Ensure shader directory exists +mkdir -p "$SHADER_DIR" + +# Check if shader file exists, if not create with default brightness +if [ ! -f "$SHADER_FILE" ]; then + CURRENT=1.0 +else + # Get current brightness multiplier + CURRENT=$(grep -oP 'pixColor.rgb \*= \K[0-9.]+' "$SHADER_FILE" | tail -1) +fi + +# Calculate new brightness (decrease by 10%) +NEW=$(echo "$CURRENT * 0.90" | bc -l) + +# Cap at 0.1 to prevent complete darkness +if (( $(echo "$NEW < 0.1" | bc -l) )); then + NEW=0.1 +fi + +# Format to 2 decimal places +NEW=$(printf "%.2f" "$NEW") + +# Check if blue light filter is currently enabled +BLUELIGHT_ENABLED=false +if [ -f "$SHADER_FILE" ] && grep -q "pixColor.b \*= 0.6" "$SHADER_FILE"; then + BLUELIGHT_ENABLED=true +fi + +# Recreate the shader file +cat > "$SHADER_FILE" << EOF +#version 300 es + +precision mediump float; + +in vec2 v_texcoord; +out vec4 fragColor; +uniform sampler2D tex; + +void main() { + vec4 pixColor = texture(tex, v_texcoord); + +EOF + +if [ "$BLUELIGHT_ENABLED" = true ]; then + cat >> "$SHADER_FILE" << EOF + // Reduce blue light + pixColor.r *= 1.0; + pixColor.g *= 0.85; + pixColor.b *= 0.6; + +EOF +fi + +cat >> "$SHADER_FILE" << EOF + // Adjust brightness + pixColor.rgb *= $NEW; + + fragColor = pixColor; +} +EOF + +# Apply shader +if [ -z "$HYPRLAND_INSTANCE_SIGNATURE" ]; then + export HYPRLAND_INSTANCE_SIGNATURE=$(ls -t /tmp/hypr/ 2>/dev/null | head -n1) +fi +/usr/bin/hyprctl keyword decoration:screen_shader "$SHADER_FILE" + +echo "Brightness decreased from $CURRENT to $NEW" diff --git a/br_reset.sh b/br_reset.sh new file mode 100755 index 0000000..f8c4d30 --- /dev/null +++ b/br_reset.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Path to the brightness shader file +SHADER_DIR="$HOME/.config/hypr/shaders" +SHADER_FILE="$SHADER_DIR/brightness.frag" + +# Ensure shader directory exists +mkdir -p "$SHADER_DIR" + +# Create shader file with 100% brightness and no blue light filter +cat > "$SHADER_FILE" << EOF +#version 300 es + +precision mediump float; + +in vec2 v_texcoord; +out vec4 fragColor; +uniform sampler2D tex; + +void main() { + vec4 pixColor = texture(tex, v_texcoord); + + // Adjust brightness + pixColor.rgb *= 1.00; + + fragColor = pixColor; +} +EOF + +# Apply shader +if [ -z "$HYPRLAND_INSTANCE_SIGNATURE" ]; then + export HYPRLAND_INSTANCE_SIGNATURE=$(ls -t /tmp/hypr/ 2>/dev/null | head -n1) +fi +/usr/bin/hyprctl keyword decoration:screen_shader "$SHADER_FILE" + +echo "Screen reset: Brightness 100%, Blue light filter OFF" diff --git a/br_up.sh b/br_up.sh new file mode 100755 index 0000000..88f0800 --- /dev/null +++ b/br_up.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# Path to the brightness shader file +SHADER_DIR="$HOME/.config/hypr/shaders" +SHADER_FILE="$SHADER_DIR/brightness.frag" + +# Ensure shader directory exists +mkdir -p "$SHADER_DIR" + +# Check if shader file exists, if not create with default brightness +if [ ! -f "$SHADER_FILE" ]; then + CURRENT=1.0 +else + # Get current brightness multiplier + CURRENT=$(grep -oP 'pixColor.rgb \*= \K[0-9.]+' "$SHADER_FILE" | tail -1) +fi + +# Calculate new brightness (increase by 10%) +NEW=$(echo "$CURRENT * 1.10" | bc -l) + +# Cap at 2.0 to prevent excessive brightness +if (( $(echo "$NEW > 2.0" | bc -l) )); then + NEW=2.0 +fi + +# Format to 2 decimal places +NEW=$(printf "%.2f" "$NEW") + +# Check if blue light filter is currently enabled +BLUELIGHT_ENABLED=false +if [ -f "$SHADER_FILE" ] && grep -q "pixColor.b \*= 0.6" "$SHADER_FILE"; then + BLUELIGHT_ENABLED=true +fi + +# Recreate the shader file +cat > "$SHADER_FILE" << EOF +#version 300 es + +precision mediump float; + +in vec2 v_texcoord; +out vec4 fragColor; +uniform sampler2D tex; + +void main() { + vec4 pixColor = texture(tex, v_texcoord); + +EOF + +if [ "$BLUELIGHT_ENABLED" = true ]; then + cat >> "$SHADER_FILE" << EOF + // Reduce blue light + pixColor.r *= 1.0; + pixColor.g *= 0.85; + pixColor.b *= 0.6; + +EOF +fi + +cat >> "$SHADER_FILE" << EOF + // Adjust brightness + pixColor.rgb *= $NEW; + + fragColor = pixColor; +} +EOF + +# Apply shader +if [ -z "$HYPRLAND_INSTANCE_SIGNATURE" ]; then + export HYPRLAND_INSTANCE_SIGNATURE=$(ls -t /tmp/hypr/ 2>/dev/null | head -n1) +fi +/usr/bin/hyprctl keyword decoration:screen_shader "$SHADER_FILE" + +echo "Brightness increased from $CURRENT to $NEW" diff --git a/fzf-git.sh b/fzf-git.sh new file mode 100755 index 0000000..d360751 --- /dev/null +++ b/fzf-git.sh @@ -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 diff --git a/fzf_listoldfiles.sh b/fzf_listoldfiles.sh new file mode 100755 index 0000000..0b5ffed --- /dev/null +++ b/fzf_listoldfiles.sh @@ -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 "$@" diff --git a/hydroxide.sh b/hydroxide.sh new file mode 100755 index 0000000..9bac7d5 --- /dev/null +++ b/hydroxide.sh @@ -0,0 +1,7 @@ +hydroxide serve & + +kanata --cfg ~/.config/kanata/config.kbd & + +sudo mount -a & + +syncthing & diff --git a/kanata.sh b/kanata.sh new file mode 100755 index 0000000..a6dcd61 --- /dev/null +++ b/kanata.sh @@ -0,0 +1 @@ +kanata --cfg ~/.config/kanata/config.kbd & diff --git a/keyboard-layer.sh b/keyboard-layer.sh new file mode 100755 index 0000000..f6874ed --- /dev/null +++ b/keyboard-layer.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# ~/.config/hypr/scripts/keyboard-layer.sh + +# This checks which modifiers are active as a proxy for layers +# Adjust based on your actual layer keys + +while true; do + # You might need to adjust this based on your keyboard + # This is a simplified example + echo '{"text": "Layer ?", "class": "layer"}' + sleep 0.5 +done diff --git a/layer_notify.sh b/layer_notify.sh new file mode 100755 index 0000000..5f0a3c0 --- /dev/null +++ b/layer_notify.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +case $1 in + 0) notify-send -t 1500 "Layer 0" "Base/QWERTY" ;; + 1) notify-send -t 1500 "Layer 1" "Navigation/Numbers" ;; + 2) notify-send -t 1500 "Layer 2" "Symbols" ;; + 3) notify-send -t 1500 "Layer 3" "Function Keys" ;; + *) notify-send -t 1500 "Unknown Layer" ;; +esac diff --git a/protonport.sh b/protonport.sh new file mode 100755 index 0000000..7f0d864 --- /dev/null +++ b/protonport.sh @@ -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 diff --git a/tidal-mcp.sh b/tidal-mcp.sh new file mode 100755 index 0000000..e94a51d --- /dev/null +++ b/tidal-mcp.sh @@ -0,0 +1,11 @@ +cd ~/mcp/tidal-mcp/ + +uv venv --clear +source .venv/bin/activate + +uv pip install --editable . + +cd ~/mcp/tidal-mcp/tidal_api/ +uv pip install flask tidalapi + +nohup python app.py > tidal.log 2>&1 & diff --git a/tidal.log b/tidal.log new file mode 100644 index 0000000..9b7c006 --- /dev/null +++ b/tidal.log @@ -0,0 +1,2 @@ +nohup: ignoring input +/usr/bin/python: can't open file '/home/liph/dotfiles/scripts/scripts/app.py': [Errno 2] No such file or directory diff --git a/tmux-sessionizer.sh b/tmux-sessionizer.sh new file mode 100755 index 0000000..e89f2fb --- /dev/null +++ b/tmux-sessionizer.sh @@ -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 diff --git a/zoxide_openfiles_nvim.sh b/zoxide_openfiles_nvim.sh new file mode 100755 index 0000000..3d177ed --- /dev/null +++ b/zoxide_openfiles_nvim.sh @@ -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 "$@"