diff options
Diffstat (limited to '')
-rw-r--r-- | modules/by-name/at/atuin/atuin.zsh | 126 | ||||
-rw-r--r-- | modules/by-name/at/atuin/module.nix | 6 | ||||
-rw-r--r-- | modules/by-name/lf/lf/commands/default.nix | 46 | ||||
-rwxr-xr-x | modules/by-name/lf/lf/commands/scripts/dragon.sh | 2 | ||||
-rwxr-xr-x | modules/by-name/lf/lf/commands/scripts/dragon_individual.sh | 2 | ||||
-rwxr-xr-x | modules/by-name/lf/lf/commands/scripts/dragon_stay.sh | 2 | ||||
-rw-r--r-- | modules/by-name/zs/zsh/module.nix | 19 |
7 files changed, 170 insertions, 33 deletions
diff --git a/modules/by-name/at/atuin/atuin.zsh b/modules/by-name/at/atuin/atuin.zsh new file mode 100644 index 00000000..60fb74fe --- /dev/null +++ b/modules/by-name/at/atuin/atuin.zsh @@ -0,0 +1,126 @@ +#! /usr/bin/env zsh +# shellcheck disable=SC2034,SC2153,SC2086,SC2155 + +# Above line is because shellcheck doesn't support zsh, per +# https://github.com/koalaman/shellcheck/wiki/SC1071, and the ignore: param in +# ludeeus/action-shellcheck only supports _directories_, not _files_. So +# instead, we manually add any error the shellcheck step finds in the file to +# the above line ... + +if ! [[ $options[zle] = on ]]; then + return 0 +fi + +# Source this in your ~/.zshrc +autoload -U add-zsh-hook + +zmodload zsh/datetime 2>/dev/null + +# If zsh-autosuggestions is installed, configure it to use Atuin's search. If +# you'd like to override this, then add your config after the $(atuin init zsh) +# in your .zshrc +_zsh_autosuggest_strategy_atuin() { + suggestion=$(ATUIN_QUERY="$1" atuin search --cmd-only --limit 1 --search-mode prefix) +} + +if [ -n "${ZSH_AUTOSUGGEST_STRATEGY:-}" ]; then + ZSH_AUTOSUGGEST_STRATEGY=("atuin" "${ZSH_AUTOSUGGEST_STRATEGY[@]}") +else + ZSH_AUTOSUGGEST_STRATEGY=("atuin") +fi + +export ATUIN_SESSION=$(atuin uuid) +ATUIN_HISTORY_ID="" + +_atuin_preexec() { + local id + id=$(atuin history start -- "$1") + export ATUIN_HISTORY_ID="$id" + __atuin_preexec_time=${EPOCHREALTIME-} +} + +_atuin_precmd() { + local EXIT="$?" __atuin_precmd_time=${EPOCHREALTIME-} + + [[ -z "${ATUIN_HISTORY_ID:-}" ]] && return + + local duration="" + if [[ -n $__atuin_preexec_time && -n $__atuin_precmd_time ]]; then + printf -v duration %.0f $(((__atuin_precmd_time - __atuin_preexec_time) * 1000000000)) + fi + + (ATUIN_LOG=error atuin history end --exit $EXIT ${duration:+--duration=$duration} -- $ATUIN_HISTORY_ID &) >/dev/null 2>&1 + export ATUIN_HISTORY_ID="" +} + +_atuin_search() { + emulate -L zsh + zle -I + + # swap stderr and stdout, so that the tui stuff works + # TODO: not this + local output + # shellcheck disable=SC2048 + output=$(ATUIN_SHELL_ZSH=t ATUIN_LOG=error ATUIN_QUERY=$BUFFER atuin search $* -i 3>&1 1>&2 2>&3) + + zle reset-prompt + + if [[ -n $output ]]; then + RBUFFER="" + LBUFFER=$output + + if [[ $LBUFFER == __atuin_accept__:* ]] + then + LBUFFER=${LBUFFER#__atuin_accept__:} + zle accept-line + fi + fi +} +_atuin_search_vicmd() { + _atuin_search --keymap-mode=vim-normal +} +_atuin_search_viins() { + _atuin_search --keymap-mode=vim-insert +} + +_atuin_up_search() { + # Only trigger if the buffer is a single line + if [[ ! $BUFFER == *$'\n'* ]]; then + _atuin_search --shell-up-key-binding "$@" + else + zle up-line + fi +} +_atuin_up_search_vicmd() { + _atuin_up_search --keymap-mode=vim-normal +} +_atuin_up_search_viins() { + _atuin_up_search --keymap-mode=vim-insert +} + +add-zsh-hook preexec _atuin_preexec +add-zsh-hook precmd _atuin_precmd + +zle -N atuin-search _atuin_search +zle -N atuin-search-vicmd _atuin_search_vicmd +zle -N atuin-search-viins _atuin_search_viins +zle -N atuin-up-search _atuin_up_search +zle -N atuin-up-search-vicmd _atuin_up_search_vicmd +zle -N atuin-up-search-viins _atuin_up_search_viins + +# These are compatibility widget names for "atuin <= 17.2.1" users. +zle -N _atuin_search_widget _atuin_search +zle -N _atuin_up_search_widget _atuin_up_search + +bindkey -M emacs '^r' atuin-search +bindkey -M viins '^r' atuin-search-viins +bindkey -M vicmd '/' atuin-search +bindkey -M emacs '^[[A' atuin-up-search +bindkey -M vicmd '^[[A' atuin-up-search-vicmd +bindkey -M viins '^[[A' atuin-up-search-viins +bindkey -M emacs '^[OA' atuin-up-search +bindkey -M vicmd '^[OA' atuin-up-search-vicmd +bindkey -M viins '^[OA' atuin-up-search-viins +bindkey -M vicmd 'k' atuin-up-search-vicmd + +# vim: ft=zsh diff --git a/modules/by-name/at/atuin/module.nix b/modules/by-name/at/atuin/module.nix index 604ee4ef..2061fd71 100644 --- a/modules/by-name/at/atuin/module.nix +++ b/modules/by-name/at/atuin/module.nix @@ -18,11 +18,15 @@ in { group = "users"; }; + soispha.programs.zsh.integrations.atuin = ./atuin.zsh; + home-manager.users.soispha = { programs.atuin = { enable = true; package = pkgs.atuin-dvorak; - enableZshIntegration = config.soispha.programs.zsh.enable; + + # We can do this on our own. + enableZshIntegration = false; settings = { key_path = "${config.age.secrets.atuin_encryption_key.path}"; diff --git a/modules/by-name/lf/lf/commands/default.nix b/modules/by-name/lf/lf/commands/default.nix index 9a709168..90b333c6 100644 --- a/modules/by-name/lf/lf/commands/default.nix +++ b/modules/by-name/lf/lf/commands/default.nix @@ -2,53 +2,38 @@ functionCall = { name, dependencies, - ... + keepPath ? false, }: pkgs.writeShellApplication { inherit name; text = builtins.readFile ./base.sh + builtins.readFile ./scripts/${name}.sh; - runtimeInputs = dependencies; + runtimeInputs = [pkgs.lf pkgs.mktemp pkgs.coreutils] ++ dependencies; + inheritPath = keepPath; } + "/bin/${name}"; # closes the lf tui - shell = { - name, - dependencies, - ... - }: '' + shell = args: '' ''${{ - ${functionCall {inherit name dependencies;}} + ${functionCall args} }} ''; # runs the command in the ui/term bar - pipe = { - name, - dependencies, - ... - }: '' + pipe = args: '' %{{ - ${functionCall {inherit name dependencies;}} + ${functionCall args} }} ''; # runs the command in the background - async = { - name, - dependencies, - ... - }: '' + async = args: '' &{{ - ${functionCall {inherit name dependencies;}} + ${functionCall args} }} ''; # adds a prompt after the command has run - wait = { - name, - dependencies, - ... - }: '' + wait = args: '' !{{ - ${functionCall {inherit name dependencies;}} + ${functionCall args} }} ''; in { @@ -83,20 +68,21 @@ in { dragon = pipe { name = "dragon"; - dependencies = [pkgs.xdragon]; + dependencies = [pkgs.dragon-drop]; }; dragon_individual = pipe { name = "dragon_individual"; - dependencies = [pkgs.xdragon]; + dependencies = [pkgs.dragon-drop]; }; dragon_stay = pipe { name = "dragon_stay"; - dependencies = [pkgs.xdragon]; + dependencies = [pkgs.dragon-drop]; }; execute = shell { name = "execute"; dependencies = []; + keepPath = true; }; follow_link = pipe { name = "follow_link"; @@ -118,6 +104,7 @@ in { mk_script = shell { name = "mk_script"; dependencies = []; + keepPath = true; }; set_clipboard_path = async { @@ -153,5 +140,6 @@ in { view_file = async { name = "view_file"; dependencies = with pkgs; [file]; + keepPath = true; }; } diff --git a/modules/by-name/lf/lf/commands/scripts/dragon.sh b/modules/by-name/lf/lf/commands/scripts/dragon.sh index 299d7bbe..916c09ee 100755 --- a/modules/by-name/lf/lf/commands/scripts/dragon.sh +++ b/modules/by-name/lf/lf/commands/scripts/dragon.sh @@ -13,5 +13,5 @@ while read -r file; do set -- "$@" "$file" done <"$(echo "$fx" | tmp)" -dragon --all --and-exit "$@" +dragon-drop --all --and-exit "$@" # vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/dragon_individual.sh b/modules/by-name/lf/lf/commands/scripts/dragon_individual.sh index 1cb603d9..c6b3b2a6 100755 --- a/modules/by-name/lf/lf/commands/scripts/dragon_individual.sh +++ b/modules/by-name/lf/lf/commands/scripts/dragon_individual.sh @@ -13,5 +13,5 @@ while read -r file; do set -- "$@" "$file" done <"$(echo "$fx" | tmp)" -dragon "$@" +dragon-drop "$@" # vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/dragon_stay.sh b/modules/by-name/lf/lf/commands/scripts/dragon_stay.sh index 4a16e802..7296a6b9 100755 --- a/modules/by-name/lf/lf/commands/scripts/dragon_stay.sh +++ b/modules/by-name/lf/lf/commands/scripts/dragon_stay.sh @@ -13,5 +13,5 @@ while read -r file; do set -- "$@" "$file" done <"$(echo "$fx" | tmp)" -dragon --all "$@" +dragon-drop --all "$@" # vim: ft=sh diff --git a/modules/by-name/zs/zsh/module.nix b/modules/by-name/zs/zsh/module.nix index cb1bb086..b50e72ac 100644 --- a/modules/by-name/zs/zsh/module.nix +++ b/modules/by-name/zs/zsh/module.nix @@ -10,9 +10,25 @@ zDotDir = ".config/zsh"; sourceFile = path: "source ${path}\n"; + + extraFiles = builtins.concatStringsSep "\n" ( + builtins.map sourceFile ( + builtins.attrValues cfg.integrations + ) + ); in { options.soispha.programs.zsh = { enable = lib.mkEnableOption "zsh"; + + integrations = lib.mkOption { + type = lib.types.attrsOf lib.types.path; + example = '' + { + atuin = ./integrations/atuin.zsh; + } + ''; + default = {}; + }; }; config = lib.mkIf cfg.enable { @@ -105,6 +121,9 @@ in { lib.modules.mkMerge [ start + + extraFiles + end ]; |