diff --git a/docs/alias.md b/docs/alias.md new file mode 100644 index 0000000..7c18a44 --- /dev/null +++ b/docs/alias.md @@ -0,0 +1,52 @@ +# Alias Commands + +This file lists all aliases defined in `config/alias`. + +| Alias | Command | +| ------------- | ------------------------------------------------------------------------------------------------------------------------------ | +| `....` | `cd ../../..` | +| `...` | `cd ../..` | +| `..` | `cd ..` | +| `.` | `cd $HOME` | +| `.b` | `cd $XDG_BIN_HOME` | +| `.c` | `cd $HOME/Code` | +| `.d` | `cd $DOTFILES` | +| `.l` | `cd $HOME/.local` | +| `.o` | `cd $HOME/Code/ivuorinen/obsidian/` | +| `art` | `[ -f artisan ] && php artisan \|\| php vendor/bin/artisan` | +| `cd..` | `cd ..` | +| `cdgr` | `cd "$(get_git_root)"` | +| `dn` | `du -chd1` | +| `flush` | `dscacheutil -flushcache` | +| `grep` | `grep --color` | +| `hide` | `defaults write com.apple.finder AppleShowAllFiles -bool false; killall Finder` | +| `ips` | `ifconfig -a \| grep -o 'inet6\? \(\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\)\\|[a-fA-F0-9:]\+\)' \| sed -e 's/inet6* //' \| sort` | +| `irssi` | `irssi --config=$XDG_CONFIG_HOME/irssi/config --home=$XDG_CONFIG_HOME/irssi` | +| `isodate` | `date +'%Y-%m-%d'` | +| `l` | `ls -a` | +| `ll` | `ls -la` | +| `localip` | `ipconfig getifaddr en1` | +| `mirror_site` | `wget -m -k -K -E -e robots=off` | +| `peek` | `tee >(cat 1>&2)` | +| `pubkey` | `more ~/.ssh/id_rsa.pub \| pbcopy \| echo '=> Public key copied to pasteboard.'` | +| `sail` | `[ -f sail ] && bash sail \|\| bash vendor/bin/sail` | +| `show` | `defaults write com.apple.finder AppleShowAllFiles -bool true; killall Finder` | +| `sl` | `ls` | +| `svn` | `svn --config-dir $XDG_CONFIG_HOME/subversion` | +| `trivy_scan` | `docker run -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/Library/Caches:/root/.cache/ aquasec/trivy` | +| `updatedb` | `sudo /usr/libexec/locate.updatedb` | +| `vi` | `nvim` | +| `vim` | `nvim` | +| `watchx` | `watch -dpbc` | +| `wget` | `wget --hsts-file=$XDG_DATA_HOME/wget-hsts` | +| `x-datetime` | `date +'%Y-%m-%d %H:%M:%S'` | +| `x-ip` | `dig +short myip.opendns.com @resolver1.opendns.com` | +| `x-timestamp` | `date +'%s'` | +| `xdg` | `xdg-ninja --skip-ok --skip-unsupported` | +| `zapall` | `zapds && zappyc` | +| `zapds` | `find . -name ".DS_Store" -print -delete` | +| `zappyc` | `find . -type f -name '*.pyc' -ls -delete` | +| `zedit` | `$EDITOR ~/.dotfiles` | + +Total aliases: 43 +Last updated: Fri 17 Jan 2025 13:06:59 EET diff --git a/scripts/update-readme-aliases.sh b/scripts/update-readme-aliases.sh new file mode 100755 index 0000000..0858a2a --- /dev/null +++ b/scripts/update-readme-aliases.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +# update-readme-aliases.sh +# @description Update alias documentation in $DOTFILES/docs/alias.md +# +# Author: Ismo Vuorinen 2025 +# License: MIT + +set -euo pipefail + +# Paths +ALIAS_FILE="$DOTFILES/config/alias" +OUTPUT_FILE="$DOTFILES/docs/alias.md" + +# Check if alias file exists +if [[ ! -f $ALIAS_FILE ]]; then + echo "Alias file not found: $ALIAS_FILE" + exit 1 +fi + +# Declare associative array +declare -a alias_table + +echo "Parsing aliases..." +while IFS= read -r line; do + # Skip all lines that do not start with 'alias' + if [[ ! $line =~ ^alias\ ]]; then + continue + fi + + # Split alias and command and handle both ' and " + if [[ $line =~ ^alias\ ([^=]+)=[\'\"](.*)[\'\"]$ ]]; then + alias_name="${BASH_REMATCH[1]}" + alias_command="${BASH_REMATCH[2]//|/\\|}" # fix markdown table separator + + # Save alias to table + alias_table+=("\`$alias_name\`␟\`$alias_command\`") + else + echo "Warning: Could not parse line: $line" + fi + +done < "$ALIAS_FILE" + +# Sort array by alias name +# shellcheck disable=SC2207 +IFS=$'\n' sorted_aliases=($(sort <<< "${alias_table[*]}")) +unset IFS + +# Calculate cell max lengths +max_alias_length=5 # "Alias" min length +max_command_length=7 # "Command" min length + +for entry in "${sorted_aliases[@]}"; do + IFS=$'␟' read -r alias_name alias_command <<< "$entry" + max_alias_length=$((${#alias_name} > max_alias_length ? ${#alias_name} : max_alias_length)) + max_command_length=$((${#alias_command} > max_command_length ? ${#alias_command} : max_command_length)) +done + +# Empty the markdown file and add header +printf "# Alias Commands\n\nThis file lists all aliases defined in \`config/alias\`.\n\n" > "$OUTPUT_FILE" + +# Add table header +printf "| %-*s | %-*s |\n" \ + "$max_alias_length" "Alias" \ + "$max_command_length" "Command" >> "$OUTPUT_FILE" + +# Add table header separator +printf "| %-*s | %-*s |\n" \ + "$max_alias_length" "$(printf '%0.s-' $(seq 1 $max_alias_length))" \ + "$max_command_length" "$(printf '%0.s-' $(seq 1 $max_command_length))" >> "$OUTPUT_FILE" + +# Create table with max cell lengths +for entry in "${sorted_aliases[@]}"; do + IFS=$'␟' read -r alias_name alias_command <<< "$entry" + printf "| %-*s | %-*s |\n" \ + "$max_alias_length" "$alias_name" \ + "$max_command_length" "$alias_command" >> "$OUTPUT_FILE" +done + +{ + printf "\n" + printf "Total aliases: %d\n" "${#sorted_aliases[@]}" + printf "Last updated: %s\n" "$(date)" +} >> "$OUTPUT_FILE" + +# Announce process completion +echo "Alias documentation updated: $OUTPUT_FILE"