nu: add cycling alt+. and history picker alt+,
Alt+. now cycles through all whitespace-split tokens from history (most recent first, last arg first within each command) using env var state. Alt+, opens a skim fuzzy picker over full history commands and inserts the selected entry at the cursor.
This commit is contained in:
@@ -33,14 +33,18 @@ $env.config = {
|
||||
|
||||
keybindings: [
|
||||
{
|
||||
name: insert_last_arg
|
||||
name: cycle_history_args
|
||||
modifier: alt
|
||||
keycode: char_.
|
||||
mode: [vi_insert, emacs]
|
||||
event: {
|
||||
send: executehostcommand
|
||||
cmd: "commandline edit --insert (history | last | get command | split words | last)"
|
||||
}
|
||||
event: { send: executehostcommand, cmd: "last-arg-cycle" }
|
||||
}
|
||||
{
|
||||
name: history_cmd_pick
|
||||
modifier: alt
|
||||
keycode: char_u002c
|
||||
mode: [vi_insert, emacs]
|
||||
event: { send: executehostcommand, cmd: "history-cmd-pick" }
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -25,6 +25,54 @@ def rewatch [interval: duration, cmd: closure] {
|
||||
}
|
||||
}
|
||||
|
||||
# Cycle through all history args on repeated Alt+. presses
|
||||
def --env last-arg-cycle [] {
|
||||
let skip = ["|" "&&" "||" ";" ">" ">>" "<" "&" "2>"]
|
||||
let all_args = (
|
||||
history
|
||||
| get command
|
||||
| reverse
|
||||
| each { |cmd| $cmd | split row -r '\s+' | where { |w| ($w | str length) > 0 } | reverse | where { |w| not ($skip | any { $w == $in }) } }
|
||||
| flatten
|
||||
| where { |w| ($w | str length) > 0 }
|
||||
)
|
||||
if ($all_args | is-empty) { return }
|
||||
|
||||
let current = (commandline)
|
||||
let last = ($env.NU_ALT_DOT_LAST? | default "")
|
||||
let base = ($env.NU_ALT_DOT_BASE? | default "")
|
||||
let idx = ($env.NU_ALT_DOT_IDX? | default (-1) | into int)
|
||||
|
||||
if $idx >= 0 and $current == $"($base)($last)" {
|
||||
let next_idx = (($idx + 1) mod ($all_args | length))
|
||||
let next = ($all_args | get $next_idx)
|
||||
commandline edit --replace $"($base)($next)"
|
||||
$env.NU_ALT_DOT_IDX = $next_idx
|
||||
$env.NU_ALT_DOT_LAST = $next
|
||||
} else {
|
||||
let first = ($all_args | get 0)
|
||||
commandline edit --insert $first
|
||||
$env.NU_ALT_DOT_BASE = $current
|
||||
$env.NU_ALT_DOT_IDX = 0
|
||||
$env.NU_ALT_DOT_LAST = $first
|
||||
}
|
||||
}
|
||||
|
||||
# Fuzzy-pick a full command from history and insert at cursor (Alt+,)
|
||||
def --env history-cmd-pick [] {
|
||||
let cmd = try {
|
||||
history
|
||||
| get command
|
||||
| reverse
|
||||
| uniq
|
||||
| sk --prompt "history> " --height "40%" --reverse --no-sort
|
||||
| str trim
|
||||
} catch { "" }
|
||||
if ($cmd | str length) > 0 {
|
||||
commandline edit --insert $cmd
|
||||
}
|
||||
}
|
||||
|
||||
# Environment variables as a filterable sorted table
|
||||
def envs [query?: string] {
|
||||
$env | transpose key value
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
XDG_DESKTOP_DIR="$HOME/Desktop"
|
||||
XDG_DOWNLOAD_DIR="$HOME/Downloads"
|
||||
XDG_TEMPLATES_DIR="$HOME/Templates"
|
||||
XDG_PUBLICSHARE_DIR="$HOME/Public"
|
||||
XDG_DOCUMENTS_DIR="$HOME/Documents"
|
||||
XDG_MUSIC_DIR="$HOME/Music"
|
||||
XDG_PICTURES_DIR="$HOME/Pictures"
|
||||
XDG_PUBLICSHARE_DIR="$HOME/"
|
||||
XDG_DOCUMENTS_DIR="$HOME/"
|
||||
XDG_MUSIC_DIR="$HOME/"
|
||||
XDG_PICTURES_DIR="$HOME/"
|
||||
XDG_VIDEOS_DIR="$HOME/Videos"
|
||||
XDG_PROJECTS_DIR="$HOME/Projects"
|
||||
|
||||
Reference in New Issue
Block a user