Skip to content

Commit

Permalink
Added autocompletion and a simple lfcd script for nushell. (#1341)
Browse files Browse the repository at this point in the history
* Added autocompletion and a simple lfcd script for nushell.

* nu-lfcd script & small style improvements. Moved the autocompletion to a seperate file.

* Update lfcd.nu to print to stderr instead of stdout

* Fixed the comments inside lf.nu
  • Loading branch information
mauerlaeufer authored Jul 16, 2023
1 parent a3127a2 commit 3c681c2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
29 changes: 29 additions & 0 deletions etc/lf.nu
Original file line number Diff line number Diff line change
@@ -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
]
34 changes: 34 additions & 0 deletions etc/lfcd.nu
Original file line number Diff line number Diff line change
@@ -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)'
}
}

0 comments on commit 3c681c2

Please sign in to comment.