mirror of
https://github.com/nushell/nu_scripts.git
synced 2024-08-17 01:10:36 +03:00
cwdhist: alternative to zoxide (#656)
- cwdhist: alternative to zoxide - just-completions: remove `--unstable` - kubernetes: fix desc of kdh --------- Co-authored-by: nash <nash@iffy.me>
This commit is contained in:
parent
c2bb125a67
commit
e4ae994200
@ -1,5 +1,5 @@
|
||||
def "nu-complete just recipes" [] {
|
||||
^just --unstable --unsorted --dump --dump-format json
|
||||
^just --unsorted --dump --dump-format json
|
||||
| from json
|
||||
| get recipes
|
||||
| transpose k v
|
||||
@ -22,7 +22,7 @@ def "nu-complete just recipes" [] {
|
||||
|
||||
def "nu-complete just args" [context: string, offset: int] {
|
||||
let r = ($context | split row ' ')
|
||||
^just --unstable -u --dump --dump-format json
|
||||
^just -u --dump --dump-format json
|
||||
| from json
|
||||
| get recipes
|
||||
| get ($r.1)
|
||||
|
107
modules/cwdhist/cwdhist.nu
Normal file
107
modules/cwdhist/cwdhist.nu
Normal file
@ -0,0 +1,107 @@
|
||||
def __cwdhist_menu [] {
|
||||
{
|
||||
name: cwdhist_menu
|
||||
only_buffer_difference: false
|
||||
marker: "| "
|
||||
type: {
|
||||
layout: columnar
|
||||
page_size: 20
|
||||
}
|
||||
style: {
|
||||
text: green
|
||||
selected_text: green_reverse
|
||||
description_text: yellow
|
||||
}
|
||||
source: { |buffer, position|
|
||||
#$"[($position)]($buffer);(char newline)" | save -a ~/.cache/cwdhist.log
|
||||
let cwd = if ($buffer | is-empty) {
|
||||
""
|
||||
} else {
|
||||
$buffer
|
||||
}
|
||||
if 'cwd_history_full' in $env {
|
||||
open $nu.history-path | query db $"
|
||||
select cwd as value, count\(*) as description
|
||||
from history
|
||||
where cwd like '%($cwd)%'
|
||||
group by cwd
|
||||
order by description desc
|
||||
limit 20
|
||||
;"
|
||||
} else {
|
||||
open $env.cwd_history_file | query db $"
|
||||
select cwd as value, count as description
|
||||
from cwd_history
|
||||
where cwd like '%($cwd)%'
|
||||
order by count desc
|
||||
limit 20
|
||||
;"
|
||||
}
|
||||
| append { value: '~' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def __cwdhist_keybinding [] {
|
||||
{
|
||||
name: cwdhist_menu
|
||||
modifier: control
|
||||
keycode: char_o
|
||||
mode: [emacs, vi_normal, vi_insert]
|
||||
event: [
|
||||
{ send: menu name: cwdhist_menu }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
def __edit_keybinding [] {
|
||||
{
|
||||
name: edit
|
||||
modifier: alt
|
||||
keycode: char_e
|
||||
mode: [emacs, vi_normal, vi_insert]
|
||||
event: [
|
||||
{ send: OpenEditor }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export-env {
|
||||
$env.cwd_history_file = '~/.cache/nu_cwd_history.sqlite'
|
||||
|
||||
if not ($env.cwd_history_file | path exists) {
|
||||
"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|
|
||||
if $dir == $nu.home-path { return }
|
||||
let suffix = (do --ignore-errors { $dir | path relative-to $nu.home-path })
|
||||
let path = if ($suffix | is-empty) {
|
||||
$dir
|
||||
} else {
|
||||
['~', $suffix] | path join
|
||||
}
|
||||
open $env.cwd_history_file
|
||||
| query db $"
|
||||
insert into cwd_history\(cwd)
|
||||
values \('($path)')
|
||||
on conflict\(cwd)
|
||||
do update set
|
||||
count = count + 1,
|
||||
recent = datetime\('now', 'localtime');"
|
||||
}
|
||||
|
||||
$env.config = ($env.config
|
||||
| update hooks.env_change.PWD ($env.config.hooks.env_change.PWD | append $__cwdhist_hook ))
|
||||
|
||||
$env.config = ($env.config
|
||||
| upsert menus ($env.config.menus | append (__cwdhist_menu))
|
||||
| upsert keybindings ($env.config.keybindings | append [(__cwdhist_keybinding) (__edit_keybinding)])
|
||||
)
|
||||
}
|
@ -221,7 +221,7 @@ export def kah [
|
||||
helm $act $name $chart -f $valuefile $values (spr [-n $namespace])
|
||||
}
|
||||
|
||||
# helm install or upgrade via values file
|
||||
# helm diff
|
||||
export def kdh [
|
||||
name: string@"nu-complete helm list"
|
||||
chart: string@"nu-complete helm charts"
|
||||
|
Loading…
Reference in New Issue
Block a user