From 27cf6925728c8eb9343ee9b52e8ed420aa73a07b Mon Sep 17 00:00:00 2001 From: Joey Hafner Date: Wed, 4 Sep 2024 13:06:03 -0700 Subject: [PATCH] Clean up dotfiles - Move shell profiles to shell folder - Add `ffconvert` and `zipline` functions - Delete configuration files for tools I don't use --- dotfiles/.aliases | 36 -- dotfiles/.bashrc | 33 -- dotfiles/config/discord/Breezy.theme.css | 7 - dotfiles/config/fio/fio.ini | 14 - .../markdownload/MarkDownload-settings.json | 28 -- dotfiles/shell/.aliases | 80 +++++ dotfiles/shell/.bashrc | 10 + dotfiles/shell/.shellrc | 6 + dotfiles/{ => shell}/.zshrc | 21 +- .../utility-scripts/ffmpeg/convert-to-x264 | 2 + .../utility-scripts/ffmpeg/send-to-zipline | 2 +- .../gnome/generate-symlinks.sh | 21 -- .../gnome/gnome-mute-screenshot.sh | 17 - .../gnome/nautilus-script-testing.sh | 5 - .../utility-scripts/llms/generate-symlinks.sh | 13 - ...azerViperUltimate-IndicateBatteryOnDock.sh | 87 ----- dotfiles/vscode/shellinit.sh | 334 ++++++++++++++++++ 17 files changed, 439 insertions(+), 277 deletions(-) delete mode 100644 dotfiles/.aliases delete mode 100644 dotfiles/.bashrc delete mode 100644 dotfiles/config/discord/Breezy.theme.css delete mode 100644 dotfiles/config/fio/fio.ini delete mode 100644 dotfiles/config/markdownload/MarkDownload-settings.json create mode 100644 dotfiles/shell/.aliases create mode 100644 dotfiles/shell/.bashrc create mode 100644 dotfiles/shell/.shellrc rename dotfiles/{ => shell}/.zshrc (81%) delete mode 100755 dotfiles/utility-scripts/gnome/generate-symlinks.sh delete mode 100755 dotfiles/utility-scripts/gnome/gnome-mute-screenshot.sh delete mode 100755 dotfiles/utility-scripts/gnome/nautilus-script-testing.sh delete mode 100755 dotfiles/utility-scripts/llms/generate-symlinks.sh delete mode 100755 dotfiles/utility-scripts/razer-cli/RazerViperUltimate-IndicateBatteryOnDock.sh create mode 100644 dotfiles/vscode/shellinit.sh diff --git a/dotfiles/.aliases b/dotfiles/.aliases deleted file mode 100644 index f0c262f5..00000000 --- a/dotfiles/.aliases +++ /dev/null @@ -1,36 +0,0 @@ -# Aliases -alias ls='ls --color' - -# extract a video from a clip without transcoding -# takes `--start -# --duration -# --file '' -alias clip='~/Nextcloud/Dotfiles/Fedora/clip.sh' - -# kills all processes related to lutris. must be adapted if steam is used instead -alias gamescopereset='kill $(ps aux | grep lutris | tr -s " " | cut -d" " -f 2)' -# restarts applications which break when pulseaudio devices restart -alias audiofix='systemctl --user restart pipewire-pulse.service' - -# Get the size of a remote git repository as quickly as possible. -git-getsize() { - echo "Cloning with --no-checkout ... " - git clone --no-checkout "$1" && cd "$(basename "$_" .git)" - echo "Size of LFS objects:" - git lfs ls-files -s | cut -d' ' -f4-5 - if ! [ -z ${cleanup+x} ]; then - unset cleanup - fi - while [ -z ${cleanup+x} ]; do - read -p "Clean up the git repo? [y/n]: " yn - case $yn in - [Yy]*) cleanup=0 ;; - [Nn]*) cleanup=1 ;; - *) echo "Enter y or n" ;; - esac - done -} - -# The jot command works like: -# jot 'Some note I would quickly take' -function jot () { if [ -z "$@" ]; then echo -e "Usage: jot 'Some note to take'\nRemember to use single quotes"; else echo "$@" | sed -e 's/^/- /' >> ~/Documents/Notes/Daily/$(date +%Y_%m_%d).md; fi } diff --git a/dotfiles/.bashrc b/dotfiles/.bashrc deleted file mode 100644 index 460bf4b3..00000000 --- a/dotfiles/.bashrc +++ /dev/null @@ -1,33 +0,0 @@ -# .bashrc - -# Source global definitions -if [ -f /etc/bashrc ]; then - . /etc/bashrc -fi - -# User specific environment -if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]; then - PATH="$HOME/.local/bin:$HOME/bin:$PATH" -fi -export PATH - -# Uncomment the following line if you don't like systemctl's auto-paging feature: -# export SYSTEMD_PAGER= - -# User specific aliases and functions -if [ -d ~/.bashrc.d ]; then - for rc in ~/.bashrc.d/*; do - if [ -f "$rc" ]; then - . "$rc" - fi - done -fi -unset rc -export HSA_OVERRIDE_GFX_VERSION=11.0.0 -export OLLAMA_HOST=https://ollama.jafner.net -export NVM_DIR="$HOME/.nvm" -[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm -[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion -export PYENV_ROOT="$HOME/.pyenv" -[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH" -eval "$(pyenv init -)" diff --git a/dotfiles/config/discord/Breezy.theme.css b/dotfiles/config/discord/Breezy.theme.css deleted file mode 100644 index 57ce3a0b..00000000 --- a/dotfiles/config/discord/Breezy.theme.css +++ /dev/null @@ -1,7 +0,0 @@ -/** - * @name Discord Breeze Dark - * @author Jafner - * @description Shitty attempt to replicate KDE's Breeze Dark - * @version 0.0.1 - */ - diff --git a/dotfiles/config/fio/fio.ini b/dotfiles/config/fio/fio.ini deleted file mode 100644 index 6a5cc8de..00000000 --- a/dotfiles/config/fio/fio.ini +++ /dev/null @@ -1,14 +0,0 @@ -[global] -bs=256K -iodepth=64 -direct=1 -ioengine=libaio -group_reporting -time_based -runtime=120 -numjobs=4 -name=raw-read -rw=read - -[job1] -filename=/dev/nvme1n1p1 diff --git a/dotfiles/config/markdownload/MarkDownload-settings.json b/dotfiles/config/markdownload/MarkDownload-settings.json deleted file mode 100644 index 5fded3bb..00000000 --- a/dotfiles/config/markdownload/MarkDownload-settings.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "headingStyle": "atx", - "hr": "---", - "bulletListMarker": "-", - "codeBlockStyle": "fenced", - "fence": "```", - "emDelimiter": "*", - "strongDelimiter": "**", - "linkStyle": "inlined", - "linkReferenceStyle": "full", - "imageStyle": "originalSource", - "imageRefStyle": "inlined", - "frontmatter": "---\ncreated: {date:YYYY-MM-DDTHH:mm:ss} (UTC {date:Z})\ntags: [{keywords}]\nsource: {baseURI}\nauthor: {byline}\n---\n\n# {pageTitle}\n\n> ## Excerpt\n> {excerpt}\n\n---", - "backmatter": "", - "title": "{pageTitle}", - "includeTemplate": true, - "saveAs": false, - "downloadImages": true, - "imagePrefix": "img/{pageTitle}/", - "mdClipsFolder": "MarkDownload", - "disallowedChars": "[]#^", - "downloadMode": "downloadsApi", - "turndownEscape": true, - "contextMenus": true, - "obsidianIntegration": true, - "obsidianVault": "Notes", - "obsidianFolder": "Webclips" -} \ No newline at end of file diff --git a/dotfiles/shell/.aliases b/dotfiles/shell/.aliases new file mode 100644 index 00000000..3179bc3b --- /dev/null +++ b/dotfiles/shell/.aliases @@ -0,0 +1,80 @@ +# Aliases +alias ls='ls --color' + +# Get the size of a remote git repository as quickly as possible. +function git-getsize() { + echo "Cloning with --no-checkout ... " + git clone --no-checkout "$1" && cd "$(basename "$_" .git)" + echo "Size of LFS objects:" + git lfs ls-files -s | cut -d' ' -f4-5 + if ! [ -z ${cleanup+x} ]; then + unset cleanup + fi + while [ -z ${cleanup+x} ]; do + read -p "Clean up the git repo? [y/n]: " yn + case $yn in + [Yy]*) cleanup=0 ;; + [Nn]*) cleanup=1 ;; + *) echo "Enter y or n" ;; + esac + done +} + +# Run some ffmpeg commands with only one subcommand and the file as input. +function ffconvert() { + COMMAND=$1 + FILE=$2 + + INPUT_FILE=$(realpath "$FILE") + FILE_PATH=$(dirname "$INPUT_FILE") + FILE_NAME=$(basename "$INPUT_FILE") + FILE_EXT="${FILE_NAME##*.}" + FILE_NAME="${FILE_NAME%.*}" + + case $COMMAND in + x264 ) OUTFILE=$(echo "$FILE_PATH/$FILE_NAME.x264.$FILE_EXT") &&\ + ffmpeg -hide_banner -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i "$INPUT_FILE" -c:v h264_vaapi -b:v 6M -maxrate 6M -c:a copy "$OUTFILE" ;; + x265 ) OUTFILE=$(echo "$FILE_PATH/$FILE_NAME.x265.$FILE_EXT") &&\ + ffmpeg -hide_banner -vaapi_device /dev/dri/renderD128 -i "$INPUT_FILE" -vf 'format=hwupload' -c:v hevc_vaapi -b:v 6M -c:a copy "$OUTFILE" ;; + av1 ) OUTFILE=$(echo "$FILE_PATH/$FILE_NAME.av1.$FILE_EXT") &&\ + ffmpeg -hide_banner -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i "$INPUT_FILE" -map 0 -vf 'format=nv12,hwupload' -c:v av1_vaapi -crf 18 -b:v 6000k "$OUTFILE" > /dev/null ;; + mp4 ) OUTFILE=$(echo "$FILE_PATH/$FILE_NAME.mp4") &&\ + ffmpeg -hide_banner -i "$INPUT_FILE" -map 0 -c:v copy -c:a copy "$OUTFILE" ;; + * ) echo "Usage: $0 (x264|x265|av1|mp4) (file)" ;; + esac +} + +# Upload a file to Zipline +# Requires: +# Zipline server located at $ZIPLINE_HOST_ROOT +# Zipline upload auth token at $HOME/.zipline-auth.token +function zipline() { + FILE=$1 + + INPUT_FILE=$(realpath "$FILE") + FILE_NAME=$(basename "$INPUT_FILE") + FILE_NAME="${FILE_NAME%.*}" + + ZIPLINE_HOST_ROOT=https://zipline.jafner.net + TOKEN=$(cat ~/.zipline-auth.token) + LINK=$(curl \ + --header "authorization: $TOKEN" \ + $ZIPLINE_HOST_ROOT/api/upload -F "file=@$INPUT_FILE" \ + --header "Content-Type: multipart/form-data" \ + --header "Format: name" \ + --header "Embed: true" \ + --header "Original-Name: true") + LINK=$(echo "$LINK" | jq -r .'files[0]') + echo "[$FILE_NAME]($LINK)" | wl-copy +} + +# The jot command works like: +# jot 'Some note I would quickly take' +function jot () { + if [ -z "$@" ]; then + echo -e "Usage: jot 'Some note to take'\nRemember to use single quotes" + else + echo "$@" |\ + sed -e 's/^/- /' >> ~/Documents/Notes/Daily/$(date +%Y_%m_%d).md + fi +} diff --git a/dotfiles/shell/.bashrc b/dotfiles/shell/.bashrc new file mode 100644 index 00000000..4412053a --- /dev/null +++ b/dotfiles/shell/.bashrc @@ -0,0 +1,10 @@ +# .bashrc + +SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")" +source $SCRIPT_PATH/.shellrc +source $SCRIPT_PATH/.aliases + +# Source global definitions +if [ -f /etc/bashrc ]; then + source /etc/bashrc +fi \ No newline at end of file diff --git a/dotfiles/shell/.shellrc b/dotfiles/shell/.shellrc new file mode 100644 index 00000000..e401eacc --- /dev/null +++ b/dotfiles/shell/.shellrc @@ -0,0 +1,6 @@ +# User specific environment +if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]; then + PATH="$HOME/.local/bin:$HOME/bin:$PATH" +fi +export PATH + diff --git a/dotfiles/.zshrc b/dotfiles/shell/.zshrc similarity index 81% rename from dotfiles/.zshrc rename to dotfiles/shell/.zshrc index 73bd978b..6b2b37ae 100644 --- a/dotfiles/.zshrc +++ b/dotfiles/shell/.zshrc @@ -1,3 +1,8 @@ +# .zshrc + +source ${0:a:h}/.shellrc +source ${0:a:h}/.aliases + # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc. # Initialization code that may require console input (password prompts, [y/n] # confirmations, etc.) must go above this block; everything else may go below. @@ -25,16 +30,6 @@ zinit light zsh-users/zsh-syntax-highlighting zinit light zsh-users/zsh-completions zinit light zsh-users/zsh-autosuggestions zinit light jirutka/zsh-shift-select -#zinit light Aloxaf/fzf-tab - -# Add in snippets -#zinit snippet OMZP::git -#zinit snippet OMZP::sudo -#zinit snippet OMZP::archlinux -#zinit snippet OMZP::aws -#zinit snippet OMZP::kubectl -#zinit snippet OMZP::kubectx -#zinit snippet OMZP::command-not-found # Load completions autoload -Uz compinit && compinit @@ -55,9 +50,7 @@ bindkey '^[[F' end-of-line # End bindkey '^[w' kill-region bindkey '^I^I' autosuggest-accept bindkey '^[' autosuggest-clear - -#bindkey '[1;6C' shift-select-word-right -#bindkey '[1;6D' shift-select-word-left +bindkey '[3~' delete-char # Delete # History HISTSIZE=5000 @@ -76,8 +69,6 @@ setopt hist_find_no_dups zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" zstyle ':completion:*' menu no -#zstyle ':fzf-tab:complete:cd:*' fzf-preview 'ls --color $realpath' -#zstyle ':fzf-tab:complete:__zoxide_z:*' fzf-preview 'ls --color $realpath' # Shell integrations eval "$(zoxide init --cmd cd zsh)" diff --git a/dotfiles/utility-scripts/ffmpeg/convert-to-x264 b/dotfiles/utility-scripts/ffmpeg/convert-to-x264 index 14de3c90..9c66a2d2 100755 --- a/dotfiles/utility-scripts/ffmpeg/convert-to-x264 +++ b/dotfiles/utility-scripts/ffmpeg/convert-to-x264 @@ -39,3 +39,5 @@ OUTFILE=$(echo "$FILE_PATH/$FILE_NAME.x264.$FILE_EXT") notify-send -t 2000 "Transcode starting" "$FILE_NAME" ffmpeg -hide_banner -vaapi_device /dev/dri/renderD128 -i "$INPUT_FILE" -c:v h264_vaapi -qp $RATE_FACTOR -c:a copy "$OUTFILE" notify-send -t 4000 "Transcode complete" "$FILE_NAME" + +ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i input.mp4 -c:v h264_vaapi -b:v 2M -maxrate 2M output.mp4 \ No newline at end of file diff --git a/dotfiles/utility-scripts/ffmpeg/send-to-zipline b/dotfiles/utility-scripts/ffmpeg/send-to-zipline index 2f8b8813..1c6d26ca 100755 --- a/dotfiles/utility-scripts/ffmpeg/send-to-zipline +++ b/dotfiles/utility-scripts/ffmpeg/send-to-zipline @@ -22,7 +22,7 @@ FILE_NAME=$(basename "$INPUT_FILE") FILE_NAME="${FILE_NAME%.*}" ZIPLINE_HOST_ROOT=https://zipline.jafner.net -TOKEN=$(cat ~/.zipline-auth) +TOKEN=$(cat ~/.zipline-auth.token) LINK=$(curl \ --header "authorization: $TOKEN" \ $ZIPLINE_HOST_ROOT/api/upload -F "file=@$INPUT_FILE" \ diff --git a/dotfiles/utility-scripts/gnome/generate-symlinks.sh b/dotfiles/utility-scripts/gnome/generate-symlinks.sh deleted file mode 100755 index 05ff14b7..00000000 --- a/dotfiles/utility-scripts/gnome/generate-symlinks.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -NAUTILUS_SCRIPTS_DIR="/home/joey/.local/share/nautilus/scripts" -COUNTER=0 -SCOUNTER=0 -DCOUNTER=0 -for file in ./*; do - # Get second line of file - SCRIPT_NAME="$(head -2 $file | tail -1)" - # Guard statement for script name - if [[ "$SCRIPT_NAME" == "#[\""* ]]; then - NAME="$(echo $SCRIPT_NAME | cut -d'"' -f 2)" - echo "ln -s $(realpath $file) \"$NAUTILUS_SCRIPTS_DIR/$NAME\"" - ln -s $(realpath $file) "$NAUTILUS_SCRIPTS_DIR/$NAME" && COUNTER=$((COUNTER+1)) || DCOUNTER=$((DCOUNTER+1)) - else - echo -n "File has no script name (Skipping): " - echo "$file" - SCOUNTER=$((SCOUNTER+1)) - fi -done -echo "Created $COUNTER new symlinks ($SCOUNTER skipped, $DCOUNTER duplicates)" \ No newline at end of file diff --git a/dotfiles/utility-scripts/gnome/gnome-mute-screenshot.sh b/dotfiles/utility-scripts/gnome/gnome-mute-screenshot.sh deleted file mode 100755 index 4cf16e7d..00000000 --- a/dotfiles/utility-scripts/gnome/gnome-mute-screenshot.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -THEME_DIR=~/.local/share/sounds/__custom -mkdir -p $THEME_DIR && cd $THEME_DIR - -touch $THEME_DIR/.disabled - -cat << 'EOF' > $THEME_DIR/index.theme -[Sound Theme] -Name=__custom -Inherits=freedesktop -Directories= -EOF - -gsettings set org.gnome.desktop.sound theme-name '__custom' - - diff --git a/dotfiles/utility-scripts/gnome/nautilus-script-testing.sh b/dotfiles/utility-scripts/gnome/nautilus-script-testing.sh deleted file mode 100755 index 6203dd99..00000000 --- a/dotfiles/utility-scripts/gnome/nautilus-script-testing.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" > ~/Nextcloud/Dotfiles/Fedora/test.txt - -#if (( $(grep -c . <<<"$(cat ~/Nextcloud/Dotfiles/Fedora/test.txt)") > 1 )); then echo "Multiline" > ~/Nextcloud/Dotfiles/Fedora/result.txt; else echo "Single line" > ~/Nextcloud/Dotfiles/Fedora/result.txt; fi -#if (( $(grep -c . <<<"$(cat ~/.nautilus_script_selected_file_paths)") > 1 )); then echo "Multiline" > ~/Nextcloud/Dotfiles/Fedora/result.txt; else echo "Single line" > ~/Nextcloud/Dotfiles/Fedora/result.txt; fi diff --git a/dotfiles/utility-scripts/llms/generate-symlinks.sh b/dotfiles/utility-scripts/llms/generate-symlinks.sh deleted file mode 100755 index 0e318d38..00000000 --- a/dotfiles/utility-scripts/llms/generate-symlinks.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# Comma-separated list of paths to which each of the model gguf files should be symlinked -LINKED_PATHS="/home/joey/Projects/LLMs/models" - -IFS="," read -ra DIR <<< "$LINKED_PATHS" -for dir in "${DIR[@]}"; do - echo "======== GENERATING SYMLINKS FOR: $dir ========" - for file in *.gguf; do - #echo "CMD: ln -s \"$(realpath $file)\" \"$dir/$file\"" - ln -s "$(realpath $file)" "$dir/$file" - done -done diff --git a/dotfiles/utility-scripts/razer-cli/RazerViperUltimate-IndicateBatteryOnDock.sh b/dotfiles/utility-scripts/razer-cli/RazerViperUltimate-IndicateBatteryOnDock.sh deleted file mode 100755 index 53a05b10..00000000 --- a/dotfiles/utility-scripts/razer-cli/RazerViperUltimate-IndicateBatteryOnDock.sh +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/bash - -debug=true # set to true if you want to see debug messages -# Find your values from the output of `razer-cli -ls` - -# These devices are queried for the charge value used to set the RGB color -device_name="Razer Viper Ultimate (Wireless)" -device_name_alternate="Razer Viper Ultimate (Wired)" - -# This device gets its RGB set based on the charge value. -# This *can* be the same as one of the above, but I like to see the RGB on my dock. -# You could also use a non-Razer device by changing the command at the end of -# the set_color_from_charge function to one which works for your device. -dock_name="Razer Mouse Dock" - -# Set the colors to use for full charge and low charge below. -# These are used to create a gradient to represent partial charge levels. -# E.g. if full charge is green and low charge is red, 50% charge will be yellow -# Or e.g. if full charge is purple (102, 0, 255) and low charge is cyan (0, 255, 255) -# then 50% charge will be a sky blue (51, 127, 255). -# You can use the rgb output of a tool like this: -# https://www.w3schools.com/colors/colors_picker.asp -full_charge_color_code="85 255 0" -low_charge_color_code="255 0 0" - -# Razer devices often have different names when they're plugged in. -# But we still want to know the charge level while we're charging, so we query both names. -low_charge_percent=$(razer-cli -d "$device_name" --battery low | grep "low threshold" | tr -s ' ' | cut -d' ' -f 4) -if [[ -z $low_charge_percent ]]; then - low_charge_percent=$(razer-cli -d "$device_name_alternate" --battery low | grep "low threshold" | tr -s ' ' | cut -d' ' -f 4) -fi - -# This is just for the math to get the color gradients. -charge_range=$((100 - $low_charge_percent)) -full_r=$(echo "$full_charge_color_code" | cut -d' ' -f 1) -low_r=$(echo "$low_charge_color_code" | cut -d' ' -f 1) -color_range_r=$(($full_r - $low_r)) - -full_g=$(echo "$full_charge_color_code" | cut -d' ' -f 2) -low_g=$(echo "$low_charge_color_code" | cut -d' ' -f 2) -color_range_g=$(($full_g - $low_g)) - -full_b=$(echo "$full_charge_color_code" | cut -d' ' -f 3) -low_b=$(echo "$low_charge_color_code" | cut -d' ' -f 3) -color_range_b=$(($full_b - $low_b)) - -# Some debug echoes. -if [[ $debug -eq "true" ]]; then - echo "full_r: $full_r, low_r: $low_r, color_range_r: $color_range_r" - echo "full_g: $full_g, low_g: $low_g, color_range_g: $color_range_g" - echo "full_b: $full_b, low_b: $low_b, color_range_b: $color_range_b" -fi - -# Our function for setting the new RGB color -# Uses a gradient between the "full" and "low" charge colors. -function set_color_from_charge () { - charge_scaled=$(($(($(($1 - $low_charge_percent)) * 100)) / $charge_range)) - r=$(($low_r + $(($(($charge_scaled * $color_range_r)) / 100)))) - g=$(($low_g + $(($(($charge_scaled * $color_range_g)) / 100)))) - b=$(($low_b + $(($(($charge_scaled * $color_range_b)) / 100)))) - - if [[ $debug -eq "true" ]]; then - echo "charge scaled: $charge_scaled" - echo "new color: $r, $g, $b" - fi - razer-cli -d $dock_name -c $r $g $b -} - -# Our main loop. Get current charge level. -# If it's reporting zero, we assume it's asleep. -# If it's reporting at or below the low battery threshold, we use the low battery color -# If it's reporting above the low battery threshold, we set the RGB color based on our gradient -# Consider adding logic to handle distinction between discharging (normal) and charging. -while true; do - charge=$(razer-cli -d "$device_name" --battery print | grep charge | tr -s ' ' | cut -d' ' -f 3) - if [[ $debug -eq "true" ]]; then - echo "charge: $charge" - fi - if [[ $charge -eq 0 ]]; then - echo "Device charge 0. Assuming the device is sleeping. Do nothing." - elif [[ $charge -lt $low_charge_percent ]]; then - razer-cli -d $dock_name -c $full_charge_color_code - else - set_color_from_charge $charge - fi - sleep 600 -done diff --git a/dotfiles/vscode/shellinit.sh b/dotfiles/vscode/shellinit.sh new file mode 100644 index 00000000..aad118a4 --- /dev/null +++ b/dotfiles/vscode/shellinit.sh @@ -0,0 +1,334 @@ +# --------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# --------------------------------------------------------------------------------------------- + +# Prevent the script recursing when setting up +if [[ -n "${VSCODE_SHELL_INTEGRATION:-}" ]]; then + builtin return +fi + +VSCODE_SHELL_INTEGRATION=1 + +# Run relevant rc/profile only if shell integration has been injected, not when run manually +if [ "$VSCODE_INJECTION" == "1" ]; then + if [ -z "$VSCODE_SHELL_LOGIN" ]; then + if [ -r ~/.bashrc ]; then + . ~/.bashrc + fi + else + # Imitate -l because --init-file doesn't support it: + # run the first of these files that exists + if [ -r /etc/profile ]; then + . /etc/profile + fi + # execute the first that exists + if [ -r ~/.bash_profile ]; then + . ~/.bash_profile + elif [ -r ~/.bash_login ]; then + . ~/.bash_login + elif [ -r ~/.profile ]; then + . ~/.profile + fi + builtin unset VSCODE_SHELL_LOGIN + + # Apply any explicit path prefix (see #99878) + if [ -n "${VSCODE_PATH_PREFIX:-}" ]; then + export PATH=$VSCODE_PATH_PREFIX$PATH + builtin unset VSCODE_PATH_PREFIX + fi + fi + builtin unset VSCODE_INJECTION +fi + +if [ -z "$VSCODE_SHELL_INTEGRATION" ]; then + builtin return +fi + +# Apply EnvironmentVariableCollections if needed +if [ -n "${VSCODE_ENV_REPLACE:-}" ]; then + IFS=':' read -ra ADDR <<< "$VSCODE_ENV_REPLACE" + for ITEM in "${ADDR[@]}"; do + VARNAME="$(echo $ITEM | cut -d "=" -f 1)" + VALUE="$(echo -e "$ITEM" | cut -d "=" -f 2-)" + export $VARNAME="$VALUE" + done + builtin unset VSCODE_ENV_REPLACE +fi +if [ -n "${VSCODE_ENV_PREPEND:-}" ]; then + IFS=':' read -ra ADDR <<< "$VSCODE_ENV_PREPEND" + for ITEM in "${ADDR[@]}"; do + VARNAME="$(echo $ITEM | cut -d "=" -f 1)" + VALUE="$(echo -e "$ITEM" | cut -d "=" -f 2-)" + export $VARNAME="$VALUE${!VARNAME}" + done + builtin unset VSCODE_ENV_PREPEND +fi +if [ -n "${VSCODE_ENV_APPEND:-}" ]; then + IFS=':' read -ra ADDR <<< "$VSCODE_ENV_APPEND" + for ITEM in "${ADDR[@]}"; do + VARNAME="$(echo $ITEM | cut -d "=" -f 1)" + VALUE="$(echo -e "$ITEM" | cut -d "=" -f 2-)" + export $VARNAME="${!VARNAME}$VALUE" + done + builtin unset VSCODE_ENV_APPEND +fi + +__vsc_get_trap() { + # 'trap -p DEBUG' outputs a shell command like `trap -- '…shellcode…' DEBUG`. + # The terms are quoted literals, but are not guaranteed to be on a single line. + # (Consider a trap like $'echo foo\necho \'bar\''). + # To parse, we splice those terms into an expression capturing them into an array. + # This preserves the quoting of those terms: when we `eval` that expression, they are preserved exactly. + # This is different than simply exploding the string, which would split everything on IFS, oblivious to quoting. + builtin local -a terms + builtin eval "terms=( $(trap -p "${1:-DEBUG}") )" + # |________________________| + # | + # \-------------------*--------------------/ + # terms=( trap -- '…arbitrary shellcode…' DEBUG ) + # |____||__| |_____________________| |_____| + # | | | | + # 0 1 2 3 + # | + # \--------*----/ + builtin printf '%s' "${terms[2]:-}" +} + +__vsc_escape_value_fast() { + builtin local LC_ALL=C out + out=${1//\\/\\\\} + out=${out//;/\\x3b} + builtin printf '%s\n' "${out}" +} + +# The property (P) and command (E) codes embed values which require escaping. +# Backslashes are doubled. Non-alphanumeric characters are converted to escaped hex. +__vsc_escape_value() { + # If the input being too large, switch to the faster function + if [ "${#1}" -ge 2000 ]; then + __vsc_escape_value_fast "$1" + builtin return + fi + + # Process text byte by byte, not by codepoint. + builtin local LC_ALL=C str="${1}" i byte token out='' + + for (( i=0; i < "${#str}"; ++i )); do + byte="${str:$i:1}" + + # Escape backslashes, semi-colons specially, then special ASCII chars below space (0x20) + if [ "$byte" = "\\" ]; then + token="\\\\" + elif [ "$byte" = ";" ]; then + token="\\x3b" + elif (( $(builtin printf '%d' "'$byte") < 31 )); then + token=$(builtin printf '\\x%02x' "'$byte") + else + token="$byte" + fi + + out+="$token" + done + + builtin printf '%s\n' "${out}" +} + +# Send the IsWindows property if the environment looks like Windows +if [[ "$(uname -s)" =~ ^CYGWIN*|MINGW*|MSYS* ]]; then + builtin printf '\e]633;P;IsWindows=True\a' + __vsc_is_windows=1 +else + __vsc_is_windows=0 +fi + +# Allow verifying $BASH_COMMAND doesn't have aliases resolved via history when the right HISTCONTROL +# configuration is used +if [[ "$HISTCONTROL" =~ .*(erasedups|ignoreboth|ignoredups).* ]]; then + __vsc_history_verify=0 +else + __vsc_history_verify=1 +fi + +__vsc_initialized=0 +__vsc_original_PS1="$PS1" +__vsc_original_PS2="$PS2" +__vsc_custom_PS1="" +__vsc_custom_PS2="" +__vsc_in_command_execution="1" +__vsc_current_command="" + +# It's fine this is in the global scope as it getting at it requires access to the shell environment +__vsc_nonce="$VSCODE_NONCE" +unset VSCODE_NONCE + +# Report continuation prompt +builtin printf "\e]633;P;ContinuationPrompt=$(echo "$PS2" | sed 's/\x1b/\\\\x1b/g')\a" + +__vsc_report_prompt() { + # Expand the original PS1 similarly to how bash would normally + # See https://stackoverflow.com/a/37137981 for technique + if ((BASH_VERSINFO[0] >= 5 || (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 4))); then + __vsc_prompt=${__vsc_original_PS1@P} + else + __vsc_prompt=${__vsc_original_PS1} + fi + + __vsc_prompt="$(builtin printf "%s" "${__vsc_prompt//[$'\001'$'\002']}")" + builtin printf "\e]633;P;Prompt=%s\a" "$(__vsc_escape_value "${__vsc_prompt}")" +} + +__vsc_prompt_start() { + builtin printf '\e]633;A\a' +} + +__vsc_prompt_end() { + builtin printf '\e]633;B\a' +} + +__vsc_update_cwd() { + if [ "$__vsc_is_windows" = "1" ]; then + __vsc_cwd="$(cygpath -m "$PWD")" + else + __vsc_cwd="$PWD" + fi + builtin printf '\e]633;P;Cwd=%s\a' "$(__vsc_escape_value "$__vsc_cwd")" +} + +__vsc_command_output_start() { + if [[ -z "$__vsc_first_prompt" ]]; then + builtin return + fi + builtin printf '\e]633;E;%s;%s\a' "$(__vsc_escape_value "${__vsc_current_command}")" $__vsc_nonce + builtin printf '\e]633;C\a' +} + +__vsc_continuation_start() { + builtin printf '\e]633;F\a' +} + +__vsc_continuation_end() { + builtin printf '\e]633;G\a' +} + +__vsc_command_complete() { + if [[ -z "$__vsc_first_prompt" ]]; then + builtin return + fi + if [ "$__vsc_current_command" = "" ]; then + builtin printf '\e]633;D\a' + else + builtin printf '\e]633;D;%s\a' "$__vsc_status" + fi + __vsc_update_cwd +} +__vsc_update_prompt() { + # in command execution + if [ "$__vsc_in_command_execution" = "1" ]; then + # Wrap the prompt if it is not yet wrapped, if the PS1 changed this this was last set it + # means the user re-exported the PS1 so we should re-wrap it + if [[ "$__vsc_custom_PS1" == "" || "$__vsc_custom_PS1" != "$PS1" ]]; then + __vsc_original_PS1=$PS1 + __vsc_custom_PS1="\[$(__vsc_prompt_start)\]$__vsc_original_PS1\[$(__vsc_prompt_end)\]" + PS1="$__vsc_custom_PS1" + fi + if [[ "$__vsc_custom_PS2" == "" || "$__vsc_custom_PS2" != "$PS2" ]]; then + __vsc_original_PS2=$PS2 + __vsc_custom_PS2="\[$(__vsc_continuation_start)\]$__vsc_original_PS2\[$(__vsc_continuation_end)\]" + PS2="$__vsc_custom_PS2" + fi + __vsc_in_command_execution="0" + fi +} + +__vsc_precmd() { + __vsc_command_complete "$__vsc_status" + __vsc_current_command="" + __vsc_report_prompt + __vsc_first_prompt=1 + __vsc_update_prompt +} + +__vsc_preexec() { + __vsc_initialized=1 + if [[ ! $BASH_COMMAND == __vsc_prompt* ]]; then + # Use history if it's available to verify the command as BASH_COMMAND comes in with aliases + # resolved + if [ "$__vsc_history_verify" = "1" ]; then + __vsc_current_command="$(builtin history 1 | sed 's/ *[0-9]* *//')" + else + __vsc_current_command=$BASH_COMMAND + fi + else + __vsc_current_command="" + fi + __vsc_command_output_start +} + +# Debug trapping/preexec inspired by starship (ISC) +if [[ -n "${bash_preexec_imported:-}" ]]; then + __vsc_preexec_only() { + if [ "$__vsc_in_command_execution" = "0" ]; then + __vsc_in_command_execution="1" + __vsc_preexec + fi + } + precmd_functions+=(__vsc_prompt_cmd) + preexec_functions+=(__vsc_preexec_only) +else + __vsc_dbg_trap="$(__vsc_get_trap DEBUG)" + + if [[ -z "$__vsc_dbg_trap" ]]; then + __vsc_preexec_only() { + if [ "$__vsc_in_command_execution" = "0" ]; then + __vsc_in_command_execution="1" + __vsc_preexec + fi + } + trap '__vsc_preexec_only "$_"' DEBUG + elif [[ "$__vsc_dbg_trap" != '__vsc_preexec "$_"' && "$__vsc_dbg_trap" != '__vsc_preexec_all "$_"' ]]; then + __vsc_preexec_all() { + if [ "$__vsc_in_command_execution" = "0" ]; then + __vsc_in_command_execution="1" + __vsc_preexec + builtin eval "${__vsc_dbg_trap}" + fi + } + trap '__vsc_preexec_all "$_"' DEBUG + fi +fi + +__vsc_update_prompt + +__vsc_restore_exit_code() { + return "$1" +} + +__vsc_prompt_cmd_original() { + __vsc_status="$?" + __vsc_restore_exit_code "${__vsc_status}" + # Evaluate the original PROMPT_COMMAND similarly to how bash would normally + # See https://unix.stackexchange.com/a/672843 for technique + local cmd + for cmd in "${__vsc_original_prompt_command[@]}"; do + eval "${cmd:-}" + done + __vsc_precmd +} + +__vsc_prompt_cmd() { + __vsc_status="$?" + __vsc_precmd +} + +# PROMPT_COMMAND arrays and strings seem to be handled the same (handling only the first entry of +# the array?) +__vsc_original_prompt_command=${PROMPT_COMMAND:-} + +if [[ -z "${bash_preexec_imported:-}" ]]; then + if [[ -n "${__vsc_original_prompt_command:-}" && "${__vsc_original_prompt_command:-}" != "__vsc_prompt_cmd" ]]; then + PROMPT_COMMAND=__vsc_prompt_cmd_original + else + PROMPT_COMMAND=__vsc_prompt_cmd + fi +fi