Skip to content

Commit

Permalink
Added autocompletion and a simple lfcd script for nushell.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauerlaeufer committed Jul 12, 2023
1 parent a3127a2 commit 92ced54
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
25 changes: 25 additions & 0 deletions etc/lf.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Autocompletion for nushell.
#
# Documentation: https://www.nushell.sh/book/externs.html

# Either add this to your existing completions or copy this to
# your nu config file (Use 'config nu' in the nushell to open it).

module completions {
export extern "lf" [
--command # command to execute on client initialization
--config # path to the config file (instead of the usual paths)
--cpuprofile # path to the file to write the CPU profile
--doc # show documentation
--last-dir-path # path to the file to write the last dir on exit (to use for cd)
--log # path to the log file to write messages
--memprofile # path to the file to write the memory profile
--remote # send remote command to server
--selection-path # 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
]
}
use completions *
36 changes: 36 additions & 0 deletions etc/lfcd.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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)";
let cmd = $'-last-dir-path=($tmp)';
run-external 'lf' $cmd;
if ($tmp | path exists) {
let dir = $"(cat $tmp)";
rm -f $"$tmp";
if ($dir | path exists) {
if ( $dir != $"pwd" ) {
cd $dir;
}
}
}
}

0 comments on commit 92ced54

Please sign in to comment.