forked from nushell/nu_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
powerline : NU_POWER_MODE and NU_POWER_BENCHMARK (nushell#464)
* powerline : NU_POWER_MODE and NU_POWER_BENCHMARK * zoxide-menu * direnv * dynamic-load * logtime --------- Co-authored-by: agent <agent@nuc>
- Loading branch information
Showing
10 changed files
with
311 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
def __zoxide_menu [] { | ||
{ | ||
name: zoxide_menu | ||
only_buffer_difference: true | ||
marker: "| " | ||
type: { | ||
layout: columnar | ||
page_size: 20 | ||
} | ||
style: { | ||
text: green | ||
selected_text: green_reverse | ||
description_text: yellow | ||
} | ||
source: { |buffer, position| | ||
zoxide query -ls $buffer | ||
| parse -r '(?P<description>[0-9]+) (?P<value>.+)' | ||
} | ||
} | ||
} | ||
|
||
def __zoxide_keybinding [] { | ||
{ | ||
name: zoxide_menu | ||
modifier: control | ||
keycode: char_o | ||
mode: [emacs, vi_normal, vi_insert] | ||
event: [ | ||
{ send: menu name: zoxide_menu } | ||
] | ||
} | ||
} | ||
|
||
def __edit_keybinding [] { | ||
{ | ||
name: edit | ||
modifier: alt | ||
keycode: char_e | ||
mode: [emacs, vi_normal, vi_insert] | ||
event: [ | ||
{ send: OpenEditor } | ||
] | ||
} | ||
} | ||
|
||
export-env { | ||
let-env config = ($env.config | ||
| upsert menus ($env.config.menus | append (__zoxide_menu)) | ||
| upsert keybindings ($env.config.keybindings | append [(__zoxide_keybinding) (__edit_keybinding)]) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
def direnv [] { | ||
[ | ||
{ | ||
condition: {|before, after| ($before != $after) and ($after | path join .env.yaml | path exists) } | ||
code: " | ||
open .env.yaml | load-env | ||
" | ||
} | ||
{ | ||
condition: {|before, after| ($before != $after) and ($after | path join '.env' | path exists) } | ||
code: " | ||
open .env | ||
| lines | ||
| parse -r '(?P<k>.+?)=(?P<v>.+)' | ||
| reduce -f {} {|x, acc| $acc | upsert $x.k $x.v} | ||
| load-env | ||
" | ||
} | ||
] | ||
} | ||
|
||
export-env { | ||
let-env config = ( $env.config | upsert hooks.env_change.PWD { |config| | ||
let o = ($config | get -i hooks.env_change.PWD) | ||
let val = (direnv) | ||
if $o == $nothing { | ||
$val | ||
} else { | ||
$o | append $val | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
def dynamic_load [] { | ||
[ | ||
{ | ||
condition: {|before, after| (not ('.nu' in (overlay list))) and ('~/.nu' | path exists) } | ||
code: "overlay use ~/.nu as .nu" | ||
} | ||
] | ||
} | ||
|
||
export-env { | ||
let-env config = ( $env.config | upsert hooks.env_change.PWD { |config| | ||
let o = ($config | get -i hooks.env_change.PWD) | ||
let val = (dynamic_load) | ||
if $o == $nothing { | ||
$val | ||
} else { | ||
$o | append $val | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
def "nu-complete ps" [] { | ||
ps | each {|x| { value: $x.pid, description: $x.name } } | ||
ps -l | each {|x| { value: $"($x.pid)", description: $x.command } } | ||
} | ||
|
||
# after <pid> { do something ... } | ||
export def main [pid: string@"nu-complete ps" action ] { | ||
# after { do something ... } <pid> | ||
export def main [action, pid: string@"nu-complete ps"] { | ||
do -i { tail --pid $pid -f /dev/null } | ||
do $action | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
def logtime [msg act] { | ||
let start = (date now) | ||
let result = (do $act) | ||
let period = ((date now) - $start | ||
| into duration -c ns | ||
| into string | ||
| str replace ' ' '') | ||
|
||
echo $'($start | date format '%Y-%m-%d_%H:%M:%S%z')(char tab)($period)(char tab)($msg)(char newline)' | ||
| save -a ~/.cache/nushell/time.log | ||
|
||
return $result | ||
} | ||
|
||
export def timelog [] { | ||
open ~/.cache/nushell/time.log | ||
| from tsv -n | ||
| rename start duration message | ||
| each {|x| | ||
$x | ||
| update start ($x.start | into datetime -f '%Y-%m-%d_%H:%M:%S%z') | ||
| update duration ($x.duration | into duration) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.