diff --git a/.envrc b/.envrc index ce4386f..42366c9 100644 --- a/.envrc +++ b/.envrc @@ -1,5 +1,5 @@ -if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then - source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=" +if ! has nix_direnv_version || ! nix_direnv_version 2.3.0; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.3.0/direnvrc" "sha256-Dmd+j63L84wuzgyjITIfSxSD57Tx7v51DMxVZOsiUD8=" fi nix_direnv_watch_file devenv.nix diff --git a/nix/home-manager/flake.lock b/nix/home-manager/flake.lock index 72bff44..ae07e5c 100644 --- a/nix/home-manager/flake.lock +++ b/nix/home-manager/flake.lock @@ -220,11 +220,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1681202837, - "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", "owner": "numtide", "repo": "flake-utils", - "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", "type": "github" }, "original": { @@ -238,11 +238,11 @@ "systems": "systems_2" }, "locked": { - "lastModified": 1692799911, - "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", "owner": "numtide", "repo": "flake-utils", - "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", "type": "github" }, "original": { @@ -310,7 +310,7 @@ }, "haumea": { "inputs": { - "nixpkgs": "nixpkgs_3" + "nixpkgs": "nixpkgs_2" }, "locked": { "lastModified": 1685133229, @@ -334,11 +334,11 @@ ] }, "locked": { - "narHash": "sha256-eqZng5dZnAUyb7xXyFk5z871GY/++KVv3Gyld5mVh20=", - "rev": "5171f5ef654425e09d9c2100f856d887da595437", - "revCount": 3003, + "narHash": "sha256-pv2k/5FvyirDE8g4TNehzwZ0T4UOMMmqWSQnM/luRtE=", + "rev": "d9b88b43524db1591fb3d9410a21428198d75d49", + "revCount": 3012, "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/nix-community/home-manager/0.1.3003%2Brev-5171f5ef654425e09d9c2100f856d887da595437/018a87e1-42f9-7e3f-99b2-eaa579c1d052/source.tar.gz" + "url": "https://api.flakehub.com/f/pinned/nix-community/home-manager/0.1.3012%2Brev-d9b88b43524db1591fb3d9410a21428198d75d49/018a94c1-1ec2-7028-a144-2f795d1470a4/source.tar.gz" }, "original": { "type": "tarball", @@ -400,7 +400,9 @@ "flake-utils": "flake-utils_2", "format-all": "format-all", "nix-straight": "nix-straight", - "nixpkgs": "nixpkgs_2", + "nixpkgs": [ + "nixpkgs" + ], "nose": "nose", "ob-racket": "ob-racket", "org": "org", @@ -414,11 +416,11 @@ "ws-butler": "ws-butler" }, "locked": { - "lastModified": 1694363072, - "narHash": "sha256-Fbdoekfrp37qrIYh8u6pAeQ4/MHCXlYKB9N420gByz0=", + "lastModified": 1694741217, + "narHash": "sha256-PsyQbRMvc/+5QXS5eahj6aS9xkp+eyOWO3nQ0uzqR/Y=", "owner": "nix-community", "repo": "nix-doom-emacs", - "rev": "34d8f65194514c041e7286215c52cf58ae682314", + "rev": "e0c972b33eb6715d4a59b7de656008609f8d77bd", "type": "github" }, "original": { @@ -517,11 +519,11 @@ "nmt": "nmt" }, "locked": { - "lastModified": 1694355499, - "narHash": "sha256-J790cxiwKFt45SQgvP4dIjQeJrU+GSk/4M93vRF5nLY=", + "lastModified": 1694701284, + "narHash": "sha256-oX5fxA/iJKSA5u4uInoC7D6S8q2YalYqUCmMbrx7SQw=", "owner": "nixneovim", "repo": "nixneovim", - "rev": "ceb8ec31b3b7ee6e8da0c5be5c5bb686c8e5dcf4", + "rev": "6942bb144608ff955b51d40ef97f0567b44b7698", "type": "github" }, "original": { @@ -543,11 +545,11 @@ "poetry2nix": "poetry2nix" }, "locked": { - "lastModified": 1694355415, - "narHash": "sha256-vQ4SyuOKZQEU3VoKDYe1I7833AoyYdFrTPRxwOUQRV8=", + "lastModified": 1694701249, + "narHash": "sha256-qei+jACFtKOnDsxOfiQIHdZW1ZubyOo06u9BtFkgvyw=", "owner": "nixneovim", "repo": "nixneovimplugins", - "rev": "566412004fdc17af693d58818b4b2b09ded5274f", + "rev": "ad967e1a8c38ace325258597731053b40b3840f9", "type": "github" }, "original": { @@ -605,21 +607,6 @@ } }, "nixpkgs_2": { - "locked": { - "lastModified": 1694343207, - "narHash": "sha256-jWi7OwFxU5Owi4k2JmiL1sa/OuBCQtpaAesuj5LXC8w=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "78058d810644f5ed276804ce7ea9e82d92bee293", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "nixpkgs-unstable", - "type": "indirect" - } - }, - "nixpkgs_3": { "locked": { "lastModified": 1681001314, "narHash": "sha256-5sDnCLdrKZqxLPK4KA8+f4A3YKO/u6ElpMILvX0g72c=", @@ -634,7 +621,7 @@ "type": "github" } }, - "nixpkgs_4": { + "nixpkgs_3": { "locked": { "narHash": "sha256-lHJ+A9esOz9vln/3CJG23FV6Wd2OoOFbDeEs4cMGMqc=", "rev": "3a2786eea085f040a66ecde1bc3ddc7099f6dbeb", @@ -714,11 +701,11 @@ "org": { "flake": false, "locked": { - "lastModified": 1694257022, - "narHash": "sha256-4Kz/du+7BcAw1m6AwPGI+MQu8ndefIPbkcdZN9tgRxM=", + "lastModified": 1694696773, + "narHash": "sha256-lgrfqX5YCRXZSyLHyRpYIQf+DOpHswPm7Vcw3WUCRAk=", "owner": "emacs-straight", "repo": "org-mode", - "rev": "2030c111eb659ece1f6fa6770658707762b83b95", + "rev": "765a84ea252fd7f281340c40fdc97f696f8cac33", "type": "github" }, "original": { @@ -830,11 +817,11 @@ "revealjs": { "flake": false, "locked": { - "lastModified": 1681386605, - "narHash": "sha256-9Q7aWgjAV37iJp6oYDz45e8J+RKwKY1Uvgg/BXwf5nQ=", + "lastModified": 1694600616, + "narHash": "sha256-R599Zdw9YzID7CRzWRcasz+ZZvZiagBFsuDWUvnNX4o=", "owner": "hakimel", "repo": "reveal.js", - "rev": "0301ce58ab185f7191696e16b1b6389f58df2892", + "rev": "a4b7f9dff7ef360afdb6d0cb53fd89063cbe0b66", "type": "github" }, "original": { @@ -850,7 +837,7 @@ "nix-doom-emacs": "nix-doom-emacs", "nix-index-database": "nix-index-database", "nixneovim": "nixneovim", - "nixpkgs": "nixpkgs_4" + "nixpkgs": "nixpkgs_3" } }, "rotate-text": { diff --git a/nix/home-manager/flake.nix b/nix/home-manager/flake.nix index a928631..fb48301 100644 --- a/nix/home-manager/flake.nix +++ b/nix/home-manager/flake.nix @@ -17,6 +17,9 @@ }; nix-doom-emacs = { url = "github:nix-community/nix-doom-emacs"; + inputs = { + nixpkgs.follows = "nixpkgs"; + }; }; nixneovim = { url = "github:nixneovim/nixneovim"; diff --git a/zsh/completions/_gh b/zsh/completions/_gh new file mode 100644 index 0000000..41cf353 --- /dev/null +++ b/zsh/completions/_gh @@ -0,0 +1,205 @@ +#compdef gh + +# zsh completion for gh -*- shell-script -*- + +__gh_debug() +{ + local file="$BASH_COMP_DEBUG_FILE" + if [[ -n ${file} ]]; then + echo "$*" >> "${file}" + fi +} + +_gh() +{ + local shellCompDirectiveError=1 + local shellCompDirectiveNoSpace=2 + local shellCompDirectiveNoFileComp=4 + local shellCompDirectiveFilterFileExt=8 + local shellCompDirectiveFilterDirs=16 + + local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace + local -a completions + + __gh_debug "\n========= starting completion logic ==========" + __gh_debug "CURRENT: ${CURRENT}, words[*]: ${words[*]}" + + # 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]}") + __gh_debug "Truncated words[*]: ${words[*]}," + + lastParam=${words[-1]} + lastChar=${lastParam[-1]} + __gh_debug "lastParam: ${lastParam}, lastChar: ${lastChar}" + + # For zsh, when completing a flag with an = (e.g., gh -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[1]} __complete ${words[2,-1]}" + if [ "${lastChar}" = "" ]; then + # If the last parameter is complete (there is a space following it) + # We add an extra empty parameter so we can indicate this to the go completion code. + __gh_debug "Adding extra empty parameter" + requestComp="${requestComp} \"\"" + fi + + __gh_debug "About to call: eval ${requestComp}" + + # Use eval to handle any environment variables and such + out=$(eval ${requestComp} 2>/dev/null) + __gh_debug "completion output: ${out}" + + # Extract the directive integer following a : from the last line + local lastLine + while IFS='\n' read -r line; do + lastLine=${line} + done < <(printf "%s\n" "${out[@]}") + __gh_debug "last line: ${lastLine}" + + if [ "${lastLine[1]}" = : ]; then + directive=${lastLine[2,-1]} + # Remove the directive including the : and the newline + local suffix + (( suffix=${#lastLine}+2)) + out=${out[1,-$suffix]} + else + # There is no directive specified. Leave $out as is. + __gh_debug "No directive found. Setting do default" + directive=0 + fi + + __gh_debug "directive: ${directive}" + __gh_debug "completions: ${out}" + __gh_debug "flagPrefix: ${flagPrefix}" + + if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then + __gh_debug "Completion received error. Ignoring completions." + return + fi + + local activeHelpMarker="_activeHelp_ " + local endIndex=${#activeHelpMarker} + local startIndex=$((${#activeHelpMarker}+1)) + local hasActiveHelp=0 + while IFS='\n' read -r comp; do + # Check if this is an activeHelp statement (i.e., prefixed with $activeHelpMarker) + if [ "${comp[1,$endIndex]}" = "$activeHelpMarker" ];then + __gh_debug "ActiveHelp found: $comp" + comp="${comp[$startIndex,-1]}" + if [ -n "$comp" ]; then + compadd -x "${comp}" + __gh_debug "ActiveHelp will need delimiter" + hasActiveHelp=1 + fi + + continue + fi + + 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/:} + + __gh_debug "Adding completion: ${comp}" + completions+=${comp} + lastComp=$comp + fi + done < <(printf "%s\n" "${out[@]}") + + # Add a delimiter after the activeHelp statements, but only if: + # - there are completions following the activeHelp statements, or + # - file completion will be performed (so there will be choices after the activeHelp) + if [ $hasActiveHelp -eq 1 ]; then + if [ ${#completions} -ne 0 ] || [ $((directive & shellCompDirectiveNoFileComp)) -eq 0 ]; then + __gh_debug "Adding activeHelp delimiter" + compadd -x "--" + hasActiveHelp=0 + fi + fi + + if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then + __gh_debug "Activating nospace." + noSpace="-S ''" + fi + + if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then + # File extension filtering + local filteringCmd + filteringCmd='_files' + for filter in ${completions[@]}; do + if [ ${filter[1]} != '*' ]; then + # zsh requires a glob pattern to do file filtering + filter="\*.$filter" + fi + filteringCmd+=" -g $filter" + done + filteringCmd+=" ${flagPrefix}" + + __gh_debug "File filtering command: $filteringCmd" + _arguments '*:filename:'"$filteringCmd" + elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then + # File completion for directories only + local subdir + subdir="${completions[1]}" + if [ -n "$subdir" ]; then + __gh_debug "Listing directories in $subdir" + pushd "${subdir}" >/dev/null 2>&1 + else + __gh_debug "Listing directories in ." + fi + + local result + _arguments '*:dirname:_files -/'" ${flagPrefix}" + result=$? + if [ -n "$subdir" ]; then + popd >/dev/null 2>&1 + fi + return $result + else + __gh_debug "Calling _describe" + if eval _describe "completions" completions $flagPrefix $noSpace; then + __gh_debug "_describe found some completions" + + # Return the success of having called _describe + return 0 + else + __gh_debug "_describe did not find completions." + __gh_debug "Checking if we should do file completion." + if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then + __gh_debug "deactivating file completion" + + # We must return an error code here to let zsh know that there were no + # completions found by _describe; this is what will trigger other + # matching algorithms to attempt to find completions. + # For example zsh can match letters in the middle of words. + return 1 + else + # Perform file completion + __gh_debug "Activating file completion" + + # We must return the result of this command, so it must be the + # last command, or else we must store its result to return it. + _arguments '*:filename:_files'" ${flagPrefix}" + fi + fi + fi +} + +# don't run the completion function when being source-ed or eval-ed +if [ "$funcstack[1]" = "_gh" ]; then + _gh +fi