Modules for Elvish Shell

Compare changes

Choose any two refs to compare.

+81 -2
README.md
··· 1 - # mellon 2 - Modules for Elvish Shell 1 + # mellon - Speak, friend, and enter 2 + 3 + Modules for [Elvish Shell](https://github.com/elves/elvish) 4 + 5 + # Install 6 + ## epm 7 + Required until git.sr.ht is added upstream: 8 + ```elvish 9 + use epm 10 + mkdir -p $epm:managed-dir/git.sr.ht/ 11 + echo "{ 12 + \"method\": \"git\", 13 + \"protocol\": \"https\", 14 + \"levels\": \"2\" 15 + }" > $epm:managed-dir/git.sr.ht/epm-domain.cfg 16 + ``` 17 + 18 + Install module 19 + ```elvish 20 + use epm 21 + epm:install &silent-if-installed=$true git.sr.ht/~ejri/mellon 22 + 23 + ``` 24 + 25 + ## NixOS 26 + 27 + `flake.nix` supplies a NixOS module that lets you import in the same manner as `epm` 28 + 29 + Input 30 + ```nix 31 + mellon.url = "git+https://git.sr.ht/~ejri/mellon"; 32 + ``` 33 + Use module 34 + ```nix 35 + { 36 + ... 37 + nixosConfigurations = { 38 + modules = [ 39 + mellon.nixosModules.default 40 + ]; 41 + }; 42 + } 43 + ``` 44 + 45 + # Usage 46 + 47 + ```elvish 48 + use git.sr.ht/~ejri/mellon/<module> 49 + ``` 50 + 51 + ## `atuin.elv` 52 + 53 + Add bindings for `Ctrl-r` and `Up` to use atuin for searching history. 54 + ```elvish 55 + if (has-external atuin) { 56 + use git.sr.ht/~ejri/mellon/atuin 57 + set edit:insert:binding[Ctrl-r] = { atuin:search } 58 + set edit:insert:binding[Up] = { atuin:search-up } 59 + } 60 + ``` 61 + 62 + ## `fzf.elv` 63 + 64 + Add bindings for `Ctrl-r` and `Up` to use fzf for searching history. 65 + ```elvish 66 + if (has-external fzf) { 67 + use git.sr.ht/~ejri/mellon/fzf 68 + set edit:insert:binding[Ctrl-r] = { fzf:history } 69 + set edit:insert:binding[Up] = { fzf:history } 70 + } 71 + ``` 72 + 73 + ## `yazi.elv` 74 + 75 + Add an alias `y` that will `cd` on quit. 76 + ```elvish 77 + if (has-external yazi) { 78 + use git.sr.ht/~ejri/mellon/yazi 79 + edit:add-var y~ $yazi:y~ 80 + } 81 + ```
+69
atuin.elv
··· 1 + use math 2 + use os 3 + use file 4 + use str 5 + 6 + set-env ATUIN_SESSION (atuin uuid) 7 + unset-env ATUIN_HISTORY_ID 8 + 9 + set edit:after-readline = [$@edit:after-readline {|line| 10 + try { 11 + if (not-eq (str:trim-space $line) '') { 12 + set-env ATUIN_HISTORY_ID (atuin history start -- $line) 13 + } 14 + } catch e { 15 + unset-env ATUIN_HISTORY_ID 16 + } 17 + }] 18 + 19 + set edit:after-command = [$@edit:after-command {|m| 20 + if (has-env ATUIN_HISTORY_ID) { 21 + var exit-status = 0 22 + if (not-eq $m[error] $nil) { 23 + if (has-key $m[error][reason] exit-status) { 24 + set exit-status = $m[error][reason][exit-status] 25 + } else { 26 + set exit-status = 127 27 + } 28 + } 29 + var duration = (exact-num (math:round (* $m[duration] 1000000000))) 30 + 31 + var history-end = { 32 + tmp E:ATUIN_LOG = 'error' 33 + atuin history end --exit $exit-status --duration $duration -- $E:ATUIN_HISTORY_ID >$os:dev-null 2>&1 34 + unset-env ATUIN_HISTORY_ID 35 + } 36 + 37 + if $notify-bg-job-success { 38 + $history-end 39 + } else { 40 + $history-end & 41 + } 42 + } 43 + }] 44 + 45 + fn search {|@argv| 46 + var accept-prefix = '__atuin_accept__:' 47 + 48 + var p = (file:pipe) 49 + # TODO: Will need an elvish flag in Atuin binary 50 + with [E:ATUIN_LOG = 'error'] [E:ATUIN_SHELL_BASH = t] [E:ATUIN_QUERY = $edit:current-command] { 51 + atuin search $@argv -i >$os:dev-tty 2>$p; edit:redraw &full=$true 52 + } 53 + file:close $p[w] 54 + var command = (str:trim-space (slurp < $p)) 55 + file:close $p[r] 56 + 57 + if (not-eq $command '') { 58 + if (str:has-prefix $command $accept-prefix) { 59 + edit:replace-input (str:trim-prefix $command $accept-prefix) 60 + edit:return-line 61 + } else { 62 + edit:replace-input $command 63 + } 64 + } 65 + } 66 + 67 + fn search-up { 68 + search --shell-up-key-binding 69 + }
+42
flake.lock
··· 1 + { 2 + "nodes": { 3 + "nixpkgs": { 4 + "locked": { 5 + "lastModified": 1764517877, 6 + "narHash": "sha256-pp3uT4hHijIC8JUK5MEqeAWmParJrgBVzHLNfJDZxg4=", 7 + "owner": "NixOS", 8 + "repo": "nixpkgs", 9 + "rev": "2d293cbfa5a793b4c50d17c05ef9e385b90edf6c", 10 + "type": "github" 11 + }, 12 + "original": { 13 + "owner": "NixOS", 14 + "ref": "nixos-unstable", 15 + "repo": "nixpkgs", 16 + "type": "github" 17 + } 18 + }, 19 + "root": { 20 + "inputs": { 21 + "nixpkgs": "nixpkgs", 22 + "systems": "systems" 23 + } 24 + }, 25 + "systems": { 26 + "locked": { 27 + "lastModified": 1681028828, 28 + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 29 + "owner": "nix-systems", 30 + "repo": "default", 31 + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 32 + "type": "github" 33 + }, 34 + "original": { 35 + "id": "systems", 36 + "type": "indirect" 37 + } 38 + } 39 + }, 40 + "root": "root", 41 + "version": 7 42 + }
+40
flake.nix
··· 1 + { 2 + inputs = { 3 + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 4 + }; 5 + 6 + outputs = 7 + { 8 + self, 9 + systems, 10 + nixpkgs, 11 + }: 12 + let 13 + eachSystem = nixpkgs.lib.genAttrs (import systems); 14 + in 15 + { 16 + packages = eachSystem ( 17 + system: 18 + let 19 + pkgs = nixpkgs.legacyPackages.${system}; 20 + in 21 + { 22 + default = pkgs.stdenv.mkDerivation { 23 + name = "mellon"; 24 + src = ./.; 25 + installPhase = '' 26 + mkdir -p $out/share/elvish/lib/git.sr.ht/~ejri/mellon 27 + cp *.elv $out/share/elvish/lib/git.sr.ht/~ejri/mellon 28 + ''; 29 + }; 30 + } 31 + ); 32 + 33 + nixosModules.default = 34 + { pkgs, ... }: 35 + { 36 + environment.systemPackages = [ self.packages.${pkgs.stdenv.hostPlatform.system}.default ]; 37 + environment.pathsToLink = [ "/share/elvish/lib/git.sr.ht/~ejri" ]; 38 + }; 39 + }; 40 + }
+3 -6
fzf.elv
··· 1 1 use str 2 2 use store 3 3 4 - fn history {|&exact=$true &edit-key='tab' &delete-key='ctrl-d' &border='rounded' &down-exit=$true| 4 + fn history {|&edit-key='tab' &delete-key='ctrl-d' &down-exit=$true @argv| 5 5 tmp E:SHELL = 'elvish' 6 6 7 7 var fzf-args = [ ··· 11 11 --print0 12 12 --info-command="print History" 13 13 --scheme=history 14 - --border=$border 15 - --query=$edit:current-command 14 + --query=$edit:current-command 15 + $@argv 16 16 ] 17 17 18 18 if (not-eq $edit-key $nil) { ··· 20 20 } 21 21 if (not-eq $delete-key $nil) { 22 22 set fzf-args = [$@fzf-args --expect=$delete-key] 23 - } 24 - if $exact { 25 - set fzf-args = [$@fzf-args --exact] 26 23 } 27 24 if $down-exit { 28 25 set fzf-args = [$@fzf-args --bind 'down:transform:if (<= $E:FZF_POS 1) { print abort } else { print down }']
+14
yazi.elv
··· 1 + use os 2 + use str 3 + use file 4 + 5 + fn y {|@argv| 6 + var tmp = (os:temp-file) 7 + yazi $@argv --cwd-file=$tmp[name] 8 + var cwd = (str:trim-space (slurp < $tmp)) 9 + file:close $tmp 10 + os:remove $tmp[name] 11 + if (and (not-eq $cwd '') (not-eq $cwd $pwd)) { 12 + cd $cwd 13 + } 14 + }