nushell config
This commit is contained in:
83
nushell/modules/pj_fzf.nu
Normal file
83
nushell/modules/pj_fzf.nu
Normal file
@@ -0,0 +1,83 @@
|
||||
# History
|
||||
const fzf_history_selector = {
|
||||
name: fzf_history_selector
|
||||
modifier: alt
|
||||
keycode: char_h
|
||||
mode: [emacs, vi_insert, vi_normal]
|
||||
event: [
|
||||
{
|
||||
send: executehostcommand
|
||||
cmd: "
|
||||
let result = history
|
||||
| reverse
|
||||
| get command
|
||||
| str replace --all (char newline) ' '
|
||||
| to text
|
||||
| fzf --height 40% --reverse --border;
|
||||
commandline edit --append $result;
|
||||
commandline set-cursor --end
|
||||
"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const fzf_file_selector = {
|
||||
name: fzf_file_selector
|
||||
modifier: alt
|
||||
keycode: char_f
|
||||
mode: [emacs, vi_insert, vi_normal]
|
||||
event: [
|
||||
{
|
||||
send: executehostcommand
|
||||
cmd: "
|
||||
let result = (ls **/* | where type == 'file' | get name | to text | fzf --height 40% --reverse --border);
|
||||
commandline edit --append $result;
|
||||
commandline set-cursor --end
|
||||
"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const fzf_dir_selector = {
|
||||
name: fzf_dir_selector
|
||||
modifier: alt
|
||||
keycode: char_d
|
||||
mode: [emacs, vi_insert, vi_normal]
|
||||
event: [
|
||||
{
|
||||
send: executehostcommand
|
||||
cmd: "
|
||||
let result = (ls **/ | where type == 'dir' | get name | to text | fzf --height 40% --reverse --border);
|
||||
commandline edit --append $result;
|
||||
commandline set-cursor --end
|
||||
"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
# Update the $env.config
|
||||
export-env {
|
||||
# Only append if not already present (check by name)
|
||||
let has_history_menu = $env.config.keybindings | any {|kb| $kb.name == "fzf_history_selector"}
|
||||
if not $has_history_menu {
|
||||
$env.config.keybindings = $env.config.keybindings | append [
|
||||
$fzf_history_selector
|
||||
]
|
||||
}
|
||||
|
||||
# Only append if not already present (check by name)
|
||||
let has_fzf_file_selector = $env.config.keybindings | any {|kb| $kb.name == "fzf_file_selector"}
|
||||
if not $has_fzf_file_selector {
|
||||
$env.config.keybindings = $env.config.keybindings | append [
|
||||
$fzf_file_selector
|
||||
]
|
||||
}
|
||||
|
||||
# Only append if not already present (check by name)
|
||||
let has_fzf_dir_selector = $env.config.keybindings | any {|kb| $kb.name == "fzf_dir_selector"}
|
||||
if not $has_fzf_dir_selector {
|
||||
$env.config.keybindings = $env.config.keybindings | append [
|
||||
$fzf_dir_selector
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user