From 7a7cd06b1827e1ad8740effa14d602af49db6e48 Mon Sep 17 00:00:00 2001 From: Sebastian Fischer Date: Sat, 7 Mar 2026 22:38:39 +0100 Subject: [PATCH] [TASK] Add aliases --- nixos/config/zsh-custom.zsh | 87 +++++++++++++++++++++++++++++++++++++ nixos/home.nix | 10 +++++ 2 files changed, 97 insertions(+) create mode 100644 nixos/config/zsh-custom.zsh diff --git a/nixos/config/zsh-custom.zsh b/nixos/config/zsh-custom.zsh new file mode 100644 index 0000000..b82871f --- /dev/null +++ b/nixos/config/zsh-custom.zsh @@ -0,0 +1,87 @@ +function cdWeb() { + cd "/mnt/data/projects/$1" || exit +} +alias www=cdWeb + +#compdef typo3 + +# This file is part of the Symfony package. +# +# (c) Fabien Potencier +# +# For the full copyright and license information, please view +# https://symfony.com/doc/current/contributing/code/license.html + +# +# zsh completions for typo3 +# +# References: +# - https://github.com/spf13/cobra/blob/master/zsh_completions.go +# - https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/Console/Resources/completion.bash +# +_sf_typo3() { + local lastParam flagPrefix requestComp out comp + local -a completions + + # The user could have moved the cursor backwards on the command-line. + # We need to trigger completion from the $CURRENT location, so we need + # to truncate the command-line ($words) up to the $CURRENT location. + # (We cannot use $CURSOR as its value does not work when a command is an alias.) + words=("${=words[1,CURRENT]}") lastParam=${words[-1]} + + # For zsh, when completing a flag with an = (e.g., typo3 -n=) + # completions must be prefixed with the flag + setopt local_options BASH_REMATCH + if [[ "${lastParam}" =~ '-.*=' ]]; then + # We are dealing with a flag with an = + flagPrefix="-P ${BASH_REMATCH}" + fi + + # Prepare the command to obtain completions + requestComp="${words[0]} ${words[1]} _complete --no-interaction -szsh -a1 -c$((CURRENT-1))" i="" + for w in ${words[@]}; do + w=$(printf -- '%b' "$w") + # remove quotes from typed values + quote="${w:0:1}" + if [ "$quote" = \' ]; then + w="${w%\'}" + w="${w#\'}" + elif [ "$quote" = \" ]; then + w="${w%\"}" + w="${w#\"}" + fi + # empty values are ignored + if [ ! -z "$w" ]; then + i="${i}-i${w} " + fi + done + + # Ensure at least 1 input + if [ "${i}" = "" ]; then + requestComp="${requestComp} -i\" \"" + else + requestComp="${requestComp} ${i}" + fi + + # Use eval to handle any environment variables and such + out=$(eval ${requestComp} 2>/dev/null) + + while IFS='\n' read -r comp; do + if [ -n "$comp" ]; then + # If requested, completions are returned with a description. + # The description is preceded by a TAB character. + # For zsh's _describe, we need to use a : instead of a TAB. + # We first need to escape any : as part of the completion itself. + comp=${comp//:/\\:} + local tab=$(printf '\t') + comp=${comp//$tab/:} + completions+=${comp} + fi + done < <(printf "%s\n" "${out[@]}") + + # Let inbuilt _describe handle completions + eval _describe "completions" completions $flagPrefix + return $? +} + +compdef _sf_typo3 typo3 diff --git a/nixos/home.nix b/nixos/home.nix index 47fa585..f4c770e 100644 --- a/nixos/home.nix +++ b/nixos/home.nix @@ -91,9 +91,19 @@ in lzd = "lazydocker"; gclb = "git-cleanup-local-branches"; ngc = "sudo nix-store --optimise && sudo nix-collect-garbage -d"; + t3docrun = "source <(docker run --rm t3docs/render-documentation show-shell-commands)"; + t3docmake = "dockrun_t3rd makehtml"; + t3docopen = ''xdg-open "file:///$(pwd)/Documentation-GENERATED-temp/Result/project/0.0.0/Index.html"''; + t3docclean = "rm -rf Documentation-GENERATED-temp/"; + t3doc = "t3docrun && t3docmake && t3docopen"; }; + home.file.".gitignore_global".text = '' + .idea + ''; + home.file.".p10k.zsh".source = ./config/p10k.zsh; + home.file.".oh-my-zsh/custom/custom.zsh".source = ./config/zsh-custom.zsh; home.file.".profile".text = '' if [ -n "$BASH_VERSION" ]; then