diff --git a/etc/lf.nu b/etc/lf.nu new file mode 100644 index 00000000..e4b1d0ff --- /dev/null +++ b/etc/lf.nu @@ -0,0 +1,29 @@ +# Autocompletion for nushell. +# +# Documentation: https://www.nushell.sh/book/externs.html + +# To enable autocompletion you may put this file into a directory: +# +# mkdir -p ~/.config/nushell/completions +# ln -s "/path/to/lf.nu" ~/.config/nushell/completions +# +# Then you need to source this file in your nu config (Open the config with the +# command 'config nu' inside the nushell) by adding: +# +# source ~/.config/nushell/completions/lf.nu + +export extern "lf" [ + --command # command to execute on client initialization + --config: string # path to the config file (instead of the usual paths) + --cpuprofile: string # path to the file to write the CPU profile + --doc # show documentation + --last-dir-path: string # path to the file to write the last dir on exit (to use for cd) + --log: string # path to the log file to write messages + --memprofile: string # path to the file to write the memory profile + --remote: string # send remote command to server + --selection-path: string # path to the file to write selected files on open (to use as open file dialog) + --server # start server (automatic) + --single # start a client without server + --version # show version + --help # show help +] diff --git a/etc/lfcd.nu b/etc/lfcd.nu new file mode 100644 index 00000000..04624ba2 --- /dev/null +++ b/etc/lfcd.nu @@ -0,0 +1,34 @@ +# Change working dir in shell to last dir in lf on exit (adapted from ranger). +# +# You need to add this to your Nushell Enviroment Config File +# (Execute 'config env' in the nushell to open it). + +# You may also like to assign a key (Ctrl-O) to this command: +# See the documentation: https://www.nushell.sh/book/line_editor.html#keybindings +# +# keybindings: [ +# { +# name: lfcd +# modifier: control +# keycode: char_o +# mode: [emacs, vi_normal, vi_insert] +# event: { +# send: executehostcommand +# cmd: "lfcd" +# } +# } +# ] + +def-env lfcd [] { + let tmp = (mktemp) + lf -last-dir-path $tmp + try { + let target_dir = (open --raw $tmp) + rm -f $tmp + try { + if ($target_dir != $env.PWD) { cd $target_dir } + } catch { |e| print -e $'lfcd: Can not change to ($target_dir): ($e | get debug)' } + } catch { + |e| print -e $'lfcd: Reading ($tmp) returned an error: ($e | get debug)' + } +}