35 lines
946 B
Plaintext
35 lines
946 B
Plaintext
|
#alias:new history edit:command-history | each [h]{ put $h['cmd'] }
|
||
|
fn history [@_args]{
|
||
|
use str
|
||
|
use moi/util/list
|
||
|
@history = (edit:command-history | each [h]{ put $h['cmd'] })
|
||
|
@ch = (list:reverse $history | list:remove-duplicate | list:reverse)
|
||
|
if (list:empty $_args) {
|
||
|
each [h]{ echo $h } $ch
|
||
|
return
|
||
|
}
|
||
|
action @rest = $_args[0] (take 1 $_args)
|
||
|
has-rest = (list:not-empty $rest)
|
||
|
if (and (is $action --cmd) $has-rest) {
|
||
|
eawk [h cmd @_]{
|
||
|
if (has-value $rest $cmd) {
|
||
|
echo $h
|
||
|
}
|
||
|
} $ch
|
||
|
} elif (and (is $action --search) $has-rest) {
|
||
|
each [h]{
|
||
|
if (list:exists [_ m]{ str:contains $h $m } $rest) {
|
||
|
echo $h
|
||
|
}
|
||
|
} $ch
|
||
|
} elif (and (is $action --delete) $has-rest) {
|
||
|
each [h]{
|
||
|
if (list:exists [_ m]{ str:contains $h $m } $rest) {
|
||
|
put $h
|
||
|
}
|
||
|
} $history
|
||
|
} else {
|
||
|
echo (styled 'Usage: history [(--search|--cmd|--delete) args...' bold red)
|
||
|
}
|
||
|
}
|