mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 07:07:46 +00:00
shift_alt_e to switch cwdhist history mode (#658)
Get cwd records in two ways: - grouping and counting `cwd` field in `history` table of `$nu.history-path` - separate `cwd_history` table in `~/.cache/nu_cwd_history.sqlite` Switch through the environment variable `cwd_history_full`, and switch this variable through `shift_alt_e` Co-authored-by: nash <nash@iffy.me>
This commit is contained in:
parent
df2556b993
commit
3dc1141403
1 changed files with 11 additions and 10 deletions
|
@ -14,7 +14,7 @@ def __cwdhist_menu [] {
|
||||||
}
|
}
|
||||||
source: { |buffer, position|
|
source: { |buffer, position|
|
||||||
#$"[($position)]($buffer);(char newline)" | save -a ~/.cache/cwdhist.log
|
#$"[($position)]($buffer);(char newline)" | save -a ~/.cache/cwdhist.log
|
||||||
if 'cwd_history_full' in $env {
|
if $env.cwd_history_full {
|
||||||
open $nu.history-path | query db $"
|
open $nu.history-path | query db $"
|
||||||
select cwd as value, count\(*) as cnt
|
select cwd as value, count\(*) as cnt
|
||||||
from history
|
from history
|
||||||
|
@ -48,20 +48,21 @@ def __cwdhist_keybinding [] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def __edit_keybinding [] {
|
def __cwdhist_switching [] {
|
||||||
{
|
{
|
||||||
name: edit
|
name: cwdhist_switching
|
||||||
modifier: alt
|
modifier: shift_alt
|
||||||
keycode: char_e
|
keycode: char_e
|
||||||
mode: [emacs, vi_normal, vi_insert]
|
mode: [emacs, vi_normal, vi_insert]
|
||||||
event: [
|
event: [
|
||||||
{ send: OpenEditor }
|
{ send: ExecuteHostCommand, cmd: '$env.cwd_history_full = (not $env.cwd_history_full)' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export-env {
|
export-env {
|
||||||
|
$env.cwd_history_full = false
|
||||||
$env.cwd_history_file = '~/.cache/nu_cwd_history.sqlite'
|
$env.cwd_history_file = '~/.cache/nu_cwd_history.sqlite'
|
||||||
|
|
||||||
if not ($env.cwd_history_file | path exists) {
|
if not ($env.cwd_history_file | path exists) {
|
||||||
|
@ -96,6 +97,6 @@ export-env {
|
||||||
|
|
||||||
$env.config = ($env.config
|
$env.config = ($env.config
|
||||||
| upsert menus ($env.config.menus | append (__cwdhist_menu))
|
| upsert menus ($env.config.menus | append (__cwdhist_menu))
|
||||||
| upsert keybindings ($env.config.keybindings | append [(__cwdhist_keybinding) (__edit_keybinding)])
|
| upsert keybindings ($env.config.keybindings | append [(__cwdhist_keybinding) (__cwdhist_switching)])
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue