diff --git a/config/fish/config.fish b/config/fish/config.fish index 20b4893..7a571a5 100755 --- a/config/fish/config.fish +++ b/config/fish/config.fish @@ -7,7 +7,6 @@ alias cv='clear && nvim' alias zs='zathura-sandbox' alias z='zathura' alias bt='bashtop' -alias vicfg='nvim ~/projects/nvim/' alias fm='thunar .' alias gl='git ls-files --others --exclude-standard' alias gm='git ls-files -m' @@ -16,23 +15,20 @@ alias gp='git pull' alias gpr='git pull --rebase' alias gc='git commit -a -m' alias ga='git add ./*' -alias cfh='nvim ~/projects/dotfiles/config/hypr/' -alias cfn='nvim ~/projects/nvim/' -alias cff='nvim ~/projects/dotfiles/config/fish/' -alias cfa='nvim ~/projects/dotfiles/config/astal/' -alias cf='nvim ~/projects/dotfiles/' +alias cfh='nvim ~/projects/system/dotfiles/config/hypr/' +alias cfn='nvim ~/projects/system/nvim/' +alias cff='nvim ~/projects/system/dotfiles/config/fish/' +alias cfa='nvim ~/projects/system/dotfiles/config/astal/' +alias cf='nvim ~/projects/system/dotfiles/' alias g='lazygit' -alias open-webui='sudo systemctl start docker && sudo docker start -i open-webui' -alias ai='ollama serve' alias ff='fastfetch' alias p='nvimpager -p' alias latexdocs='zathura ~/projects/latex/docs/docs.pdf &>> /dev/null & disown' alias gccerr='gcc -Wall -Wextra -Wpedantic -Werror -Wmissing-prototypes -std=c99' alias linecount='cloc --vcs git .' -alias flutter='fvm flutter' -# Add scripts in ~/projects/dotfiles/scripts/ to path -fish_add_path -P ~/projects/dotfiles/scripts/ +# Add custom scripts to path +fish_add_path -P ~/projects/system/dotfiles/scripts/ function y set tmp (mktemp -t "yazi-cwd.XXXXXX") diff --git a/config/hypr/hyprland.lua b/config/hypr/hyprland.lua index cdf4416..465aed8 100644 --- a/config/hypr/hyprland.lua +++ b/config/hypr/hyprland.lua @@ -1,8 +1,8 @@ -- Determine current platform local is_docked = false local laptop_config = false -local read_platform = io.popen("cat ~/.config/janishutz/platform-laptop") == "l" -local read_docked = io.popen("cat ~/.config/janishutz/docked") == "y" +local read_platform = io.popen("cat ~/.config/janishutz/platform") == "l" +local read_docked = io.popen("cat ~/.config/janishutz/docked") == "true" if read_platform then laptop_config = true diff --git a/migrate.sh b/migrate.sh deleted file mode 100755 index e1a2354..0000000 --- a/migrate.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -echo " - _ _ ( ) ( )_ - (_) _ _ ___ (_) ___| |__ _ _| _)____ - | |/ _ ) _ \ | __) _ \ ) ( ) | (_ ) - | | (_| | ( ) | |__ \ | | | (_) | |_ / /_ - _ | |\__ _)_) (_)_)____/_) (_)\___/ \__)____) -( )_| | - \___/ - - => Migration to V4 - -> WARNING: This will remove the old configurations from the system -" - - -confirmation="" -read -p "Do you really want to remove the old configuration files and update to the new configs? (y/N) " confirmation -if [[ "$confirmation" == "y" ]]; then - rm -rf ~/.config/hypr - rm ~/.config/platform - rm -rf ~/.config/rofi - rm -rf ~/.config/ags - rm -rf ~/.config/astal -else - echo "Aborting." -fi diff --git a/scripts/auto-renamer b/scripts/auto-renamer new file mode 100755 index 0000000..a86644c --- /dev/null +++ b/scripts/auto-renamer @@ -0,0 +1,5 @@ +#!/bin/sh + +SCRIPT_DIR=$(dirname "$0") + +node "$SCRIPT_DIR/util/auto-renamer/index.js" $@ diff --git a/scripts/convert-to-mp4 b/scripts/convert-to-mp4 new file mode 100755 index 0000000..64de9b8 --- /dev/null +++ b/scripts/convert-to-mp4 @@ -0,0 +1,14 @@ +#!/bin/sh + +extension="out" +read -p "Pick extension to convert from: " extension +outfolder="out" +outext="mp4" +read -p "Output folder: " outfolder +read -p "Output extension: " outext + +mkdir $outfolder +for file in *.$extension; do + ffmpeg -i "$file" "$outfolder/${file%.$extension}.$outext" + echo "\n\n==> Conversion complete\n\n" +done diff --git a/scripts/ethz-vpn b/scripts/ethz-vpn new file mode 100755 index 0000000..82da81e --- /dev/null +++ b/scripts/ethz-vpn @@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +connect() { + read -sp $'Please enter your Encryption Password: ' encpass + echo " + ==> Connecting" + TOKEN=$(cat ~/.local/share/ethz-vpn-connect/ethzvpntoken.secret | openssl enc -aes-256-cbc -pbkdf2 -d -a -k $encpass) + PASSWORD=$(cat ~/.local/share/ethz-vpn-connect/ethzvpnpass.secret | openssl enc -aes-256-cbc -pbkdf2 -d -a -k $encpass) + USERNAME=$(cat ~/.local/share/ethz-vpn-connect/ethzvpnusername.txt) + echo $PASSWORD | sudo openconnect -b -u $USERNAME@student-net.ethz.ch -g student-net --useragent=AnyConnect --no-external-auth --passwd-on-stdin --token-mode=totp --token-secret=sha1:base32:$TOKEN sslvpn.ethz.ch + if [ $? -ne 0 ]; then + echo ' ==> Failed to connect <==' + else + echo ' ==> Connected <== + ' + fi + encpass="" + PASSWORD="" + TOKEN="" +} + +disconnect() { + sudo killall -v -SIGINT openconnect + echo " ==> Disconnected" +} + +setup() { + echo 'You are about to overwrite your secrets. Press ctrl + C to cancel.' + read -p 'Please enter your ETHZ-Username: ' USERNAME + read -sp 'Please choose and enter your Encryption Password (will be required when launching): ' encpass + echo "" + read -sp 'Please enter your ETHZ WLAN (= Radius) Password: ' PASSWORD + echo "" + read -sp 'Please enter your ETHZ OTP Secret: ' TOKEN + echo "" + if [[ -d ~/.local/share/ethz-vpn-connect ]]; then + rm -rf ~/.local/share/ethz-vpn-connect + fi + mkdir ~/.local/share/ethz-vpn-connect + echo $PASSWORD | openssl enc -aes-256-cbc -pbkdf2 -a -k $encpass >~/.local/share/ethz-vpn-connect/ethzvpnpass.secret + echo $TOKEN | openssl enc -aes-256-cbc -pbkdf2 -a -k $encpass >~/.local/share/ethz-vpn-connect/ethzvpntoken.secret + echo $USERNAME >~/.local/share/ethz-vpn-connect/ethzvpnusername.txt + encpass="" + PASSWORD="" + TOKEN="" + if [ $? -ne 0 ]; then + echo ' ==> Failed to set secrets <==' + else + echo ' ==> Secrets set <==\n' + fi +} + +case "$1" in +'connect') + connect + ;; +c) + connect + ;; +'disconnect') + disconnect + ;; +d) + disconnect + ;; +dc) + disconnect + ;; +setup) + setup + ;; +*) + echo -e 'Usage: ethz-vpn [Option] \n [Option]: \n connect, c: Connect VPN \n disconnect, d, dc: Disconnect VPN \n setup: set secrets and eth-Username.\n' + ;; +esac diff --git a/scripts/pdf-wordcount b/scripts/pdf-wordcount new file mode 100755 index 0000000..3a57eae --- /dev/null +++ b/scripts/pdf-wordcount @@ -0,0 +1,3 @@ +#!/bin/sh + +echo "Word count is $(pdftotext $1 - | tr -d '.' | wc -w)" diff --git a/scripts/setup-clang-format b/scripts/setup-clang-format new file mode 100755 index 0000000..17d77e4 --- /dev/null +++ b/scripts/setup-clang-format @@ -0,0 +1,6 @@ +#!/bin/sh + + +SCRIPT_DIR=$(dirname "$0") + +cp "$SCRIPT_DIR/../linters/clang-format" ./.clang-format diff --git a/scripts/setup-eslint b/scripts/setup-eslint new file mode 100755 index 0000000..262ba18 --- /dev/null +++ b/scripts/setup-eslint @@ -0,0 +1,8 @@ +#!/bin/sh + +SCRIPT_DIR=$(dirname "$0") + +cp "$SCRIPT_DIR/../linters/eslint.config.mjs" . + +npm i --save-dev @eslint/js typescript-eslint @stylistic/eslint-plugin eslint-plugin-vue globals + diff --git a/scripts/setup-latexfmt b/scripts/setup-latexfmt new file mode 100755 index 0000000..e0c8d5f --- /dev/null +++ b/scripts/setup-latexfmt @@ -0,0 +1,6 @@ +#!/bin/sh + + +SCRIPT_DIR=$(dirname "$0") + +cp "$SCRIPT_DIR/../linters/indentconfig.yaml" ./.latexindent.yaml diff --git a/scripts/toggle-docked b/scripts/toggle-docked new file mode 100755 index 0000000..8b81771 --- /dev/null +++ b/scripts/toggle-docked @@ -0,0 +1,12 @@ +#!/bin/sh + +is_docked=$(cat ~/.config/janishutz/docked) +if [ $is_docked == "y" ]; then + echo "n" >~/.config/janishutz/docked +else + echo "y" >~/.config/janishutz/docked +fi + +hyprctl reload + +echo "Switched to docked mode" diff --git a/scripts/toggle-swapescape b/scripts/toggle-swapescape new file mode 100755 index 0000000..e20f3d4 --- /dev/null +++ b/scripts/toggle-swapescape @@ -0,0 +1,10 @@ +#!/bin/sh + +enabled=$(hyprctl getoption input:kb_options | grep "caps:swapescape") +if [[ $enabled == "" ]]; then + hyprctl keyword input:kb_options "caps:swapescape" + notify-send "Swapescape enabled" +else + hyprctl keyword input:kb_options "" + notify-send "Swapescape disabled" +fi diff --git a/scripts/update-nvim b/scripts/update-nvim new file mode 100755 index 0000000..4d6302b --- /dev/null +++ b/scripts/update-nvim @@ -0,0 +1,5 @@ +#!/bin/sh + +cd ~/projects/nvim/ +git pull +./nvim-install.sh diff --git a/scripts/util/auto-renamer/index.js b/scripts/util/auto-renamer/index.js new file mode 100644 index 0000000..4cd7444 --- /dev/null +++ b/scripts/util/auto-renamer/index.js @@ -0,0 +1,238 @@ +const fs = require('fs'); +const path = require('path'); +const { argv } = require('process'); + +const config = { + // replace character of key with value, any character, apart from ['.', '_', '-', ' '] + 'replace': { + 'ä': 'ae', + 'ö': 'oe', + 'ü': 'ue', + ',': '-', + '&': 'And', + }, + 'rules': { + 'underscore-before-and-after-number': true, // Will not do trailing or leading for filename + 'enforce-leading-zero': true, // adds a leading zero to any number below 10 + 'camel-case-rules': { + 'enforce-snake-case-for-filetypes': ['py'], // using underscores + 'enforce-kebab-case-for-filetypes': ['css', 'html', 'scss', 'tex'], // using hyphens + }, + 'file-start-letter': 'lower', // lower, upper, unchanged + 'directory-start-letter': 'upper', // lower, upper, unchanged + 'replace-dots-with': '', // will not replace as leading character to not break dotfiles + } +} + +/** + * Recursively find all files with extension in a directory + * @param {string} dir The directory to search. Either absolute or relative path + * @param {string} extension The file extension to look for + * @param {boolean} cleanup If helper files (like .DS_STORE and Windows helpers should be auto-deleted) + * @param {string[]} ignoreList A list of filenames or directories to ignore + * @returns {{ files: string, directories: string }} returns a list of html files with their full path + */ +const treeWalker = (dir, extension, cleanup, ignoreList) => { + const ls = fs.readdirSync(dir); + const fileList = []; + const dirList = []; + for (let file in ls) { + if (fs.statSync(path.join(dir, ls[file])).isDirectory()) { + // Filter ignored directories + if (ignoreList === undefined || !ignoreList.includes(ls[file])) { + const newData = treeWalker(path.join(dir, ls[file]), extension, ignoreList); + const newFiles = newData.files; + dirList.push( path.join( dir, ls[ file ] ) ); + for (let dir = 0; dir < newData.directories.length; dir++) { + dirList.push( newData.directories[dir] ); + } + for (let file = 0; file < newFiles.length; file++) { + fileList.push(newFiles[file]); + } + } + } else if (extension == '*' || ls[file].includes(extension)) { + if (ignoreList === undefined || !ignoreList.includes(ls[file])) { + fileList.push(path.join(dir, ls[file])); + } + } + } + + return { 'files': fileList, 'directories': dirList }; +} + +/** + * @param {string} filename The filename to fix according to the rules + * @returns {string} the fixed filename + */ +const fixName = ( fn, ft ) => { + let out = ''; + const enforceSnake = config.rules['camel-case-rules']['enforce-snake-case-for-filetypes'].includes( ft ); + const enforceKebab = config.rules['camel-case-rules']['enforce-kebab-case-for-filetypes'].includes( ft ); + const isDir = ft === 'directory'; + const startLetter = isDir ? config.rules['directory-start-letter'] : config.rules['file-start-letter']; + let nextUpperCase = false; + + for ( let i = 0; i < fn.length; i++ ) { + const c = fn[i]; + + if ( c == '.' ) { + // Rule: Removed after number, allowed elsewhere + if ( i > 0 && /[0-9]/.test( fn[ i - 1 ] ) ) { + out += config.rules[ 'replace-dots-with' ]; + } else { + out += '.'; + } + } else if ( /[A-Z]/.test( c ) ) { + // If we reach a capital letter and enforce either kebab-case or snake_case, we can assume that this is the start of a CamelCase word + if ( enforceKebab ) { + out += '-' + c.toLowerCase(); + } else if ( enforceSnake ) { + out += '_' + c.toLowerCase(); + } else { + nextUpperCase = false; + if ( i == 0 && startLetter === 'lower' ) { + out += c.toLowerCase(); + } else { + out += c; + } + } + } else if ( c == ' ' ) { + // We always replace spaces, the question is just to what + if ( enforceKebab ) { + out += '-'; + } else if ( enforceSnake ) { + out += '_'; + } else { + nextUpperCase = true; + } + } else if ( c == '_' ) { + // If we are not enforcing snake_case, then replace it + if ( !enforceSnake ) { + if ( needsUnderscore( i, fn ) ) { + out += '_'; + } else if ( enforceKebab ) { + out += '-'; + } else { + nextUpperCase = true; + } + } else { + out += '_' + } + } else if ( c == '-' ) { + // If we are not enforcing kebab-case + if ( !enforceKebab ) { + if ( enforceSnake ) { + out += '_'; + } else { + nextUpperCase = true; + } + } else { + out += '-' + } + } else { + let curr = config.replace[ c ] === undefined ? c : config.replace[ c ]; + if ( config.rules[ 'underscore-before-and-after-number' ] || config.rules['enforce-leading-zero'] ) { + if ( /[0-9]/.test( c ) ) { + if ( i < fn.length - 1 ) { + if ( config.rules['enforce-leading-zero'] ) { + const prevIsNumber = i > 0 && /[0-9]/.test( fn[i - 1] ); + const nextIsNumber = /[0-9]/.test( fn[i + 1] ); + if ( !nextIsNumber && ( i == 0|| !prevIsNumber ) ) { + curr = '0' + curr; + } + } + + if ( config.rules['underscore-before-and-after-number'] ) { + if ( !( /[0-9]/.test( fn[ i + 1 ] ) ) && fn[ i + 1 ] != '_' ) { + curr += '_'; + } + } + } else { + if ( config.rules['enforce-leading-zero'] && ( i > 0 && !( /[0-9]/.test( fn[i - 1] ) ) ) ) { + curr = '0' + curr; + } + } + } else { + if ( config.rules['underscore-before-and-after-number'] && /[0-9]/.test( fn[ i + 1 ] ) ) { + curr += '_'; + } + } + } + if ( nextUpperCase || ( i == 0 && startLetter === 'upper' ) ) { + nextUpperCase = false; + out += curr.toUpperCase(); + } else { + if ( i == 0 && startLetter === 'upper' ) { + out += curr.toUpperCase(); + } else { + out += curr.toLowerCase(); + } + } + } + } + return out; +} + +const needsUnderscore = ( i, fn ) => { + return ( i > 0 && /[0-9]/.test( fn[ i - 1 ] ) ) || ( i < fn - 1 && /[0-9]/.test( fn[ i + 1 ] ) ) +} + +const separateDirAndFileAndFiletype = ( filename ) => { + const loc = filename.lastIndexOf( '/' ) + 1; + let ftl = filename.lastIndexOf( '.' ) + 1; + let fn = filename.substring( loc, ftl - 1 ); + let ft = filename.substring( ftl ); + if ( fs.statSync( filename ).isDirectory() ) { + ftl = filename.length; + fn = filename.substring( loc ); + ft = 'directory'; + + } + const dir = filename.slice( 0, loc - 1 ); + return { 'filename': fn, 'dir': dir, 'filetype': ft }; +} + +const fixDirName = ( directory, top ) => { + if ( directory === top ) { + return top; + } + + const f = separateDirAndFileAndFiletype( directory ); + return fixDirName( f.dir, top ) + '/' + fixName( f.filename, f.filetype ); +} + +if (argv[2] == '-h') { + console.log('auto-renamer [directory]\n\n=> Recursively rename files in directory'); +} else if (argv[2] == '-v') { + console.log('auto-renamer version 1.0.0, developed by Janis Hutz (development@janishutz.com)'); +} else { + // Recursively add all files in the directory + const fp = path.resolve( argv[2] ); + const list = treeWalker(fp, '*', ['.git', '@girs']); + const files = list.files; + const directories = list.directories; + + for (let i = 0; i < files.length; i++) { + const file = files[i]; + const f = separateDirAndFileAndFiletype( file ); + let fixedFile = fixName( f.filename, f.filetype ); + + // Rename + const fixedPath = f.dir + '/' + fixedFile + '.' + f.filetype; + console.log( file + ' -> ' + fixedPath ); + fs.renameSync( file, fixedPath ); + } + + // Fix directory names after file names. Sort array by decending length + directories.sort( ( a, b ) => { + return b.length - a.length; + } ); + + // separate directories up until we reach the path of dir started in + for (let i = 0; i < directories.length; i++) { + const dir = directories[i]; + const fixed = fixDirName( dir, fp ); + console.log( dir + ' -> ' + fixed ); + fs.renameSync( dir, fixDirName( dir, fp ) ); + } +} diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..add2228 --- /dev/null +++ b/setup.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +echo " + _ _ ( ) ( )_ + (_) _ _ ___ (_) ___| |__ _ _| _)____ + | |/ _ ) _ \ | __) _ \ ) ( ) | (_ ) + | | (_| | ( ) | |__ \ | | | (_) | |_ / /_ + _ | |\__ _)_) (_)_)____/_) (_)\___/ \__)____) +( )_| | + \___/ + + => Migration to V4 + -> WARNING: This will remove the old configurations from the system +" + +if ! [[ -f ~/.config/janishutz/platform ]]; then + platform="" + read -p "Choose on the platform (l/D): " platform + mkdir ~/.config/janishutz + if [ $platform != "l" ]; then + platform="d" + fi + echo "$platform" >~/.config/janishutz/platform + echo "n" >~/.config/janishutz/docked +fi + +confirmation="" +read -p "Also install the system-wide environment file? (y/N) " confirmation +if [[ "$confirmation" == "y" ]]; then + sudo cp ./system/environment /etc/environment +fi + +rm -rf ~/.config/hypr +rm ~/.config/platform +rm -rf ~/.config/rofi +rm -rf ~/.config/ags +rm -rf ~/.config/astal + +cp ./config/* ~/.config