cwdhist: remove sqlite3 dependency (#661)

- empty-sqlite: dump pre-created empty sqlite database
    - rebind open_command_editor
    - typo: system-pune-all

Co-authored-by: nash <nash@iffy.me>
This commit is contained in:
fj0r 2023-11-12 00:25:50 +08:00 committed by GitHub
parent 77f7b40828
commit 27ffa41815
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -48,6 +48,16 @@ def __cwdhist_keybinding [] {
}
}
def __cwdhist_editing [] {
{
name: open_command_editor
modifier: alt
keycode: char_e
mode: [emacs, vi_normal, vi_insert]
event: { send: openeditor }
}
}
def __cwdhist_switching [] {
{
name: cwdhist_switching
@ -60,18 +70,23 @@ def __cwdhist_switching [] {
}
}
export def empty-sqlite [] {
# pre-created empty sqlite database
'H4sIAAAAAAAAA+3LQQpAYBiE4fn+bMURvhPYuIAD2MgJLChKSv9BrZ1GSrHD/n1qmtlM29Rj7H1Y1rmLXiqXmSp3SeERuzrRzfQuqJi29Fy5lO0fHgAAAAAAAAAAAAAA4LcDzTELuwAgAAA='
| decode base64 --binary | gzip -d
}
export-env {
$env.cwd_history_full = false
$env.cwd_history_file = '~/.cache/nu_cwd_history.sqlite'
if not ($env.cwd_history_file | path exists) {
"create table if not exists cwd_history (
empty-sqlite | save -f $env.cwd_history_file
open $env.cwd_history_file | query db "create table if not exists cwd_history (
cwd text primary key,
count int default 1,
recent datetime default (datetime('now', 'localtime'))
);"
| sqlite3 ~/.cache/nu_cwd_history.sqlite
}
let __cwdhist_hook = {|_, dir|
@ -97,6 +112,6 @@ export-env {
$env.config = ($env.config
| upsert menus ($env.config.menus | append (__cwdhist_menu))
| upsert keybindings ($env.config.keybindings | append [(__cwdhist_keybinding) (__cwdhist_switching)])
| upsert keybindings ($env.config.keybindings | append [(__cwdhist_keybinding) (__cwdhist_editing) (__cwdhist_switching)])
)
}

View File

@ -202,7 +202,7 @@ export def system-prune [-n: string@"nu-complete docker ns"] {
}
# system prune all
export def system-pune-all [-n: string@"nu-complete docker ns"] {
export def system-prune-all [-n: string@"nu-complete docker ns"] {
^$env.docker-cli (spr [-n $n]) system prune --all --force --volumes
}