Skip to content

Instantly share code, notes, and snippets.

@stormasm
Created January 14, 2022 17:47
Show Gist options
  • Select an option

  • Save stormasm/f09e1c5f6333ccd887b7e5cf4484eb20 to your computer and use it in GitHub Desktop.

Select an option

Save stormasm/f09e1c5f6333ccd887b7e5cf4484eb20 to your computer and use it in GitHub Desktop.
engine-q-scripts
message e-q resolution
command [alias] exists but parameter [equals] is missing in eq equals is not a parameter in engine-q
command [alias] exists but parameter [rest] is missing in eq reset renamed to initial_value
command [all?] exists but parameter [condition] is missing in eq condition renamed to predicate
command [ansi gradient] exists but parameter [rest] is missing in eq rest renamed to column path (* space in param name)
command [ansi strip] exists but parameter [rest] is missing in eq rest renamed to column path (* space in param name)
command [any?] exists but parameter [condition] is missing in eq condition renamed to predicate
command [append] exists but parameter [row value] is missing in eq row value renamed to row
command [autoenv trust] with parameter [dir] is missing in eq missing
command [autoenv trust] with parameter [quiet] is missing in eq missing
command [autoenv untrust] with parameter [dir] is missing in eq missing
command [autoenv untrust] with parameter [quiet] is missing in eq missing
command [benchmark] exists but parameter [passthrough] is missing in eq missing
command [binaryview] with parameter [bytes] is missing in eq removed from engine-q
command [binaryview] with parameter [lores] is missing in eq removed from engine-q
command [binaryview] with parameter [skip] is missing in eq removed from engine-q
command [cd] exists but parameter [directory] is missing in eq directory renamed to path
command [chart bar] with parameter [columns] is missing in eq missing
command [chart bar] with parameter [format] is missing in eq missing
command [chart bar] with parameter [acc] is missing in eq missing
command [chart bar] with parameter [use] is missing in eq missing
command [chart line] with parameter [columns] is missing in eq missing
command [chart line] with parameter [format] is missing in eq missing
command [chart line] with parameter [acc] is missing in eq missing
command [chart line] with parameter [use] is missing in eq missing
command [compact] exists but parameter [rest] is missing in eq rest renamed to columns
command [config get] with parameter [get] is missing in eq removed from engine-q
command [config remove] with parameter [remove] is missing in eq removed from engine-q
command [config set] with parameter [key] is missing in eq removed from engine-q
command [config set] with parameter [value] is missing in eq removed from engine-q
command [config set_into] with parameter [set_into] is missing in eq removed from engine-q
command [cp] exists but parameter [src] is missing in eq src renamed to source
command [cp] exists but parameter [dst] is missing in eq dst renamed to destination
command [dfr aggregate] exists but parameter [operation] is missing in eq operation renamed to operation-name
command [dfr append] exists but parameter [axis] is missing in eq missing
command [dfr cum] with parameter [type] is missing in eq cum renamed to cumulative
command [dfr cum] with parameter [reverse] is missing in eq cum renamed to cumulative
command [dfr drop-duplicates] with parameter [subset] is missing in eq missing
command [dfr drop-duplicates] with parameter [maintain] is missing in eq missing
command [dfr select] with parameter [rows] is missing in eq select renamed to get
command [dfr select] with parameter [rest] is missing in eq select renamed to get
command [dfr last] exists but parameter [n_rows] is missing in eq n_rows renamed to rows
command [dfr melt] exists but parameter [value_name] is missing in eq value_name renamed to value-name
command [dfr melt] exists but parameter [variable_name] is missing in eq variable_name renamed to variable-name
command [dfr open] exists but parameter [no_header] is missing in eq no_header reamed to no-header
command [dfr open] exists but parameter [infer_schema] is missing in eq infer_schema renamed to infer-schema
command [dfr open] exists but parameter [skip_rows] is missing in eq skip_rows renamed to skip-rows
command [dfr pivot] exists but parameter [pivot column] is missing in eq pivot column renamed to pivot-column
command [dfr pivot] exists but parameter [value column] is missing in eq value column renamed to value-column
command [dfr sample] exists but parameter [n_rows] is missing in eq n_rows renamed to n-rows
command [dfr unique] with parameter [period] is missing in eq missing
command [dfr show] with parameter [tail] is missing in eq show renamed to to-nu
command [dfr show] with parameter [n_rows] is missing in eq show renamed to to-nu
command [dfr replace] exists but parameter [length] is missing in eq missing
command [dfr replace] exists but parameter [start] is missing in eq missing
command [dfr to-csv] exists but parameter [no_header] is missing in eq no_header renamed to no-header
command [dfr where] with parameter [condition] is missing in eq missing
command [date format] exists but parameter [format] is missing in eq format renamed to format string (* space in param name)
command [date format] exists but parameter [table] is missing in eq missing
command [date humanize] with parameter [table] is missing in eq missing
command [def] exists but parameter [name] is missing in eq name renamed to def_name
command [default] with parameter [column name] is missing in eq missing
command [default] with parameter [column value] is missing in eq missing
command [detect columns] with parameter [no_headers] is missing in eq missing
command [detect columns] with parameter [skip] is missing in eq missing
command [drop nth] exists but parameter [row number] is missing in eq row number renamed to rest
command [du] with parameter [path] is missing in eq missing
command [du] with parameter [min-size] is missing in eq missing
command [du] with parameter [all] is missing in eq missing
command [du] with parameter [deref] is missing in eq missing
command [du] with parameter [exclude] is missing in eq missing
command [du] with parameter [max-depth] is missing in eq missing
command [each group] with parameter [group_size] is missing in eq missing
command [each group] with parameter [block] is missing in eq missing
command [each window] with parameter [window_size] is missing in eq missing
command [each window] with parameter [block] is missing in eq missing
command [each window] with parameter [stride] is missing in eq missing
command [empty?] with parameter [rest] is missing in eq empty? named empty in $scope.commands.signature - (* bug)
command [empty?] with parameter [block] is missing in eq empty? named empty in $scope.commands.signature - (* bug)
command [enter] exists but parameter [location] is missing in eq location renamed path
command [enter] exists but parameter [encoding] is missing in eq missing - (* may not be needed without value shells)
command [exec] with parameter [command] is missing in eq missing
command [exec] with parameter [rest] is missing in eq missing
command [exit] exists but parameter [code] is missing in eq code renamed to exit-code
command [find] with parameter [rest] is missing in eq missing
command [for] exists but parameter [var] is missing in eq var renamed to var_name
command [for] exists but parameter [in] is missing in eq in is not a parameter in engine-q
command [for] exists but parameter [value] is missing in eq value renamed to range
command [format filesize] with parameter [field] is missing in eq missing
command [format filesize] with parameter [format value] is missing in eq missing
command [from sqlite] with parameter [tables] is missing in eq missing
command [from xlsx] exists but parameter [noheaders] is missing in eq missing
command [g] exists but parameter [index] is missing in eq index renamed to shell-number
command [get] exists but parameter [rest] is missing in eq missing
command [group-by] with parameter [grouper] is missing in eq missing
command [group-by date] with parameter [column_name] is missing in eq missing
command [group-by date] with parameter [format] is missing in eq missing
command [hash] with parameter [rest] is missing in eq missing
command [hash base64] with parameter [rest] is missing in eq missing
command [hash base64] with parameter [decode] is missing in eq missing
command [hash base64] with parameter [character_set] is missing in eq missing
command [hash base64] with parameter [encode] is missing in eq missing
command [histogram] with parameter [rest] is missing in eq missing
command [histogram] with parameter [use] is missing in eq missing
command [if] exists but parameter [condition] is missing in eq condition renamed to cond
command [if] exists but parameter [then_case] is missing in eq then_case renamed to then_block
command [if] exists but parameter [else_case] is missing in eq else_case renmaed to else_expression
command [inc] exists but parameter [rest] is missing in eq missing
command [insert] with parameter [column] is missing in eq insert command replace with update comand that inserts if missing
command [insert] with parameter [value] is missing in eq insert command replace with update comand that inserts if missing
command [into column-path] with parameter [rest] is missing in eq missing
command [into path] with parameter [rest] is missing in eq missing - (* not sure if needed now)
command [keep] exists but parameter [rows] is missing in eq rows replaced with n
command [keep until] exists but parameter [condition] is missing in eq condition replaced with predicate
command [keep while] exists but parameter [condition] is missing in eq condition replaced with predicate
command [let] exists but parameter [name] is missing in eq name replaced with var_name
command [let] exists but parameter [equals] is missing in eq equals is not a parameter in engine-q
command [let] exists but parameter [expr] is missing in eq expr replaced with initial_value
command [let-env] exists but parameter [name] is missing in eq name replaced with var_name
command [let-env] exists but parameter [equals] is missing in eq equals is not a parameter in engine-q
command [let-env] exists but parameter [expr] is missing in eq expr replaced with initial_value
command [load-env] with parameter [environ] is missing in eq missing
command [ls] exists but parameter [path] is missing in eq path replaced with pattern
command [ls] exists but parameter [du] is missing in eq missing
command [match] with parameter [member] is missing in eq missing
command [match] with parameter [regex] is missing in eq missing
command [match] with parameter [invert] is missing in eq missing
command [match] with parameter [insensitive] is missing in eq missing
command [match] with parameter [multiline] is missing in eq missing
command [match] with parameter [dotall] is missing in eq missing
command [merge] with parameter [block] is missing in eq missing
command [move] with parameter [rest] is missing in eq missing
command [move] with parameter [before] is missing in eq missing
command [move] with parameter [after] is missing in eq missing
command [nth] exists but parameter [row number] is missing in eq row number replaced with rest
command [nu plugin] with parameter [load] is missing in eq missing
command [open] exists but parameter [path] is missing in eq path replaced with filename
command [open] exists but parameter [encoding] is missing in eq moved encoding to decode command
command [pathvar] with parameter [var] is missing in eq missing
command [pathvar add] with parameter [path] is missing in eq missing
command [pathvar add] with parameter [var] is missing in eq missing
command [pathvar append] with parameter [path] is missing in eq missing
command [pathvar append] with parameter [var] is missing in eq missing
command [pathvar remove] with parameter [index] is missing in eq missing
command [pathvar remove] with parameter [var] is missing in eq missing
command [pathvar reset] with parameter [var] is missing in eq missing
command [pathvar save] with parameter [var] is missing in eq missing
command [pivot] with parameter [rest] is missing in eq missing
command [pivot] with parameter [ignore-titles] is missing in eq missing
command [pivot] with parameter [header-row] is missing in eq missing
command [post] with parameter [path] is missing in eq missing
command [post] with parameter [body] is missing in eq missing
command [post] with parameter [raw] is missing in eq missing
command [post] with parameter [user] is missing in eq missing
command [post] with parameter [password] is missing in eq missing
command [post] with parameter [content-type] is missing in eq missing
command [post] with parameter [content-length] is missing in eq missing
command [prepend] exists but parameter [row value] is missing in eq row value renamed to row
command [query json] with parameter [query] is missing in eq missing
command [rename] with parameter [column_name] is missing in eq missing
command [rename] with parameter [rest] is missing in eq missing
command [roll] with parameter [by] is missing in eq missing
command [roll column] with parameter [by] is missing in eq missing
command [roll column] with parameter [cells-only] is missing in eq missing
command [roll column] with parameter [opposite] is missing in eq missing
command [roll up] with parameter [by] is missing in eq missing
command [rotate] with parameter [rest] is missing in eq missing
command [rotate counter-clockwise] with parameter [rest] is missing in eq missing
command [s3] with parameter [RESOURCE] is missing in eq missing
command [s3] with parameter [raw] is missing in eq missing
command [s3] with parameter [endpoint] is missing in eq missing
command [s3] with parameter [access_key] is missing in eq missing
command [s3] with parameter [secret_key] is missing in eq missing
command [s3] with parameter [region] is missing in eq missing
command [save] with parameter [path] is missing in eq missing
command [save] with parameter [append] is missing in eq missing
command [save] with parameter [raw] is missing in eq missing
command [select] exists but parameter [columns] is missing in eq columns renamed to rest
command [selector] with parameter [inspect] is missing in eq missing
command [selector] with parameter [query] is missing in eq missing
command [selector] with parameter [as_html] is missing in eq missing
command [selector] with parameter [attribute] is missing in eq missing
command [selector] with parameter [as_table] is missing in eq missing
command [seq] with parameter [rest] is missing in eq missing
command [seq] with parameter [widths] is missing in eq missing
command [seq] with parameter [separator] is missing in eq missing
command [seq] with parameter [terminator] is missing in eq missing
command [seq date] with parameter [reverse] is missing in eq missing
command [seq date] with parameter [separator] is missing in eq missing
command [seq date] with parameter [output-format] is missing in eq missing
command [seq date] with parameter [input-format] is missing in eq missing
command [seq date] with parameter [begin-date] is missing in eq missing
command [seq date] with parameter [end-date] is missing in eq missing
command [seq date] with parameter [increment] is missing in eq missing
command [seq date] with parameter [days] is missing in eq missing
command [skip] exists but parameter [rows] is missing in eq rows renamed to n
command [skip until] exists but parameter [condition] is missing in eq condition renamed to predicate
command [skip while] exists but parameter [condition] is missing in eq condition renamed to predicate
command [sort-by] with parameter [rest] is missing in eq missing
command [sort-by] with parameter [reverse] is missing in eq missing
command [sort-by] with parameter [insensitive] is missing in eq missing
command [split-by] with parameter [column_name] is missing in eq missing
command [start] with parameter [rest] is missing in eq missing
command [start] with parameter [application] is missing in eq missing
command [str] with parameter [rest] is missing in eq missing
command [str to-datetime] with parameter [rest] is missing in eq command replaced with into datetime
command [str to-datetime] with parameter [format] is missing in eq command replaced with into datetime
command [str to-datetime] with parameter [timezone] is missing in eq command replaced with into datetime
command [str to-datetime] with parameter [offset] is missing in eq command replaced with into datetime
command [str to-decimal] with parameter [rest] is missing in eq command replaced with into decimal
command [str to-int] with parameter [rest] is missing in eq command replaced with into int
command [str to-int] with parameter [radix] is missing in eq command replaced with into int
command [term size] with parameter [tall] is missing in eq missing
command [term size] with parameter [wide] is missing in eq missing
command [to json] exists but parameter [pretty] is missing in eq pretty missing because it defaults to pretty
command [tutor] with parameter [search] is missing in eq missing
command [tutor] with parameter [find] is missing in eq missing
command [unalias] with parameter [name] is missing in eq missing - (* replaced with hide?)
command [unlet-env] with parameter [name] is missing in eq missing - (* replaced with hide?)
command [update cells] with parameter [block] is missing in eq missing
command [update cells] with parameter [columns] is missing in eq missing
command [where] exists but parameter [condition] is missing in eq condition replaced with cond
command [which] with parameter [application] is missing in eq missing
command [which] with parameter [rest] is missing in eq missing
command [which] with parameter [all] is missing in eq missing
command [wrap] exists but parameter [column] is missing in eq column replaced with name
command [xpath] with parameter [query] is missing in eq missing
command [zip] exists but parameter [block] is missing in eq block replaced with other
# NOTE: This is meant to run with engine-q and not nushell yet
# It's still being tested. There will be bugs. :)
# REQUIREMENTS #
# you definitely need nerd fonts https://www.nerdfonts.com
# nerd fonts repo https://github.com/ryanoasis/nerd-fonts
# i use "FiraCode Nerd Font Mono" on mac
#
# you also must have the engine-q gstat plugin installed and registered
# ATTRIBUTION #
# A little fancier prompt with git information
# inspired by https://github.com/xcambar/purs
# inspired by https://github.com/IlanCosman/tide
# inspired by https://github.com/JanDeDobbeleer/oh-my-posh
# Abbreviate home path
def home_abbrev [os] {
let is_home_in_path = ($nu.cwd | str starts-with $nu.home-path)
if ($is_home_in_path == $true) {
if ($os == "Windows") {
let home = ($nu.home-path | str find-replace -a '\\' '/')
let pwd = ($nu.cwd | str find-replace -a '\\' '/')
$pwd | str find-replace $home '~'
} else {
$nu.cwd | str find-replace $nu.home-path '~'
}
} else {
$nu.cwd | str find-replace -a '\\' '/'
}
}
def path_abbrev_if_needed [apath term_width] {
# probably shouldn't do coloring here but since we're coloring
# only certain parts, it's kind of tricky to do it in another place
let T = (ansi { fg: "#BCBCBC" bg: "#3465A4"}) # truncated
let P = (ansi { fg: "#E4E4E4" bg: "#3465A4"}) # path
let PB = (ansi { fg: "#E4E4E4" bg: "#3465A4" attr: b}) # path bold
let R = (ansi reset)
if (($apath | str length) > ($term_width / 2)) {
# split out by path separator into tokens
# don't use psep here because in home_abbrev we're making them all '/'
let splits = ($apath | split row '/')
let splits_len = ($splits | length)
let subtractor = (if ($splits_len <= 2) { 1 } else { 2 })
# get all the tokens except the last
let tokens = (for x in 1..($splits_len - $subtractor) {
$"($T)((($splits) | get $x | split chars) | get 0)($R)"
})
# need an insert command
let tokens = ($tokens | prepend $"($T)~")
# append the last part of the path
let tokens = ($tokens | append $"($PB)($splits | last | get 0)($R)")
# collect
$tokens | str collect $"($T)/"
} else {
# $"($P)($apath)($R)"
# FIXME: This is close but it fails with folder with space. I'm not sure why.
# let splits = ($apath | split row '/')
# let splits_len = ($splits | length)
# let tokens = (for x in 0..($splits_len - 1) {
# if ($x < ($splits_len - 1)) {
# $"/($T)(($splits | get $x | split chars).0)($R)"
# }
# })
# let tokens = ($tokens | append $"/($PB)(($splits | last).0)($R)")
# $tokens | str collect $"($T)"
# FIXME: This is close but it fails with folder with space. I'm not sure why.
# cd "/Applications/Hex Fiend.app/"
#    ~/H/A/Hex Fiend.app 
# should be
#    ~/A/Hex Fiend.app 
let splits = ($apath | split row '/')
let splits_len = ($splits | length)
if ($splits_len == 0) {
# We're at / on the file system
$"/($T)"
} else if ($splits_len == 1) {
let top_part = ($splits | first)
let tokens = $"($PB)($top_part)($R)"
$tokens | str collect $"($T)"
} else {
let top_part = ($splits | first ($splits_len - 1))
let end_part = ($splits | last)
let tokens = (for x in $top_part {
$"/($T)(($x | split chars).0)($R)"
})
let tokens = ($tokens | append $"/($PB)($end_part.0)($R)")
$tokens | str collect $"($T)"
}
}
}
def get_index_change_count [gs] {
let index_new = ($gs | get idx_added_staged)
let index_modified = ($gs | get idx_modified_staged)
let index_deleted = ($gs | get idx_deleted_staged)
let index_renamed = ($gs | get idx_renamed)
let index_typechanged = ($gs | get idx_type_changed)
$index_new + $index_modified + $index_deleted + $index_renamed + $index_typechanged
}
def get_working_tree_count [gs] {
let wt_modified = ($gs | get wt_modified)
let wt_deleted = ($gs | get wt_deleted)
let wt_typechanged = ($gs | get wt_type_changed)
let wt_renamed = ($gs | get wt_renamed)
$wt_modified + $wt_deleted + $wt_typechanged + $wt_renamed
}
def get_conflicted_count [gs] {
($gs | get conflicts)
}
def get_untracked_count [gs] {
($gs | get wt_untracked)
}
def get_branch_name [gs] {
let br = ($gs | get branch)
if $br == "no_branch" {
""
} else {
$br
}
}
def get_ahead_count [gs] {
($gs | get ahead)
}
def get_behind_count [gs] {
($gs | get behind)
}
def get_icons_list [] {
{
AHEAD_ICON: "↑", # 2191
BEHIND_ICON: "↓", # 2193
NO_CHANGE_ICON: "✔",
HAS_CHANGE_ICON: "*",
INDEX_CHANGE_ICON: "♦",
WT_CHANGE_ICON: "✚",
CONFLICTED_CHANGE_ICON: "✖",
UNTRACKED_CHANGE_ICON: "…",
INSERT_SYMBOL_ICON: "❯",
HAMBURGER_ICON: "≡", # 2261
NOT_HAMBURGER_ICON: "≢", # 2262
GITHUB_ICON: "", # f408
BRANCH_ICON: "", # e0a0
REBASE_ICON: "", # e728
TAG_ICON: "" # f412
}
}
def get_icon_by_name [name] {
do -i { get_icons_list | get $name }
}
def get_os_icon [os] {
# f17c = tux, f179 = apple, f17a = windows
if ($os =~ Darwin) {
(char -u f179)
} else if ($os =~ Linux) {
(char -u f17c)
} else if ($os =~ Windows) {
(char -u f17a)
} else {
''
}
}
# ╭─────────────────────┬───────────────╮
# │ idx_added_staged │ 0 │ #INDEX_NEW
# │ idx_modified_staged │ 0 │ #INDEX_MODIFIED
# │ idx_deleted_staged │ 0 │ #INDEX_DELETED
# │ idx_renamed │ 0 │ #INDEX_RENAMED
# │ idx_type_changed │ 0 │ #INDEX_TYPECHANGE
# │ wt_untracked │ 0 │ #WT_NEW
# │ wt_modified │ 0 │ #WT_MODIFIED
# │ wt_deleted │ 0 │ #WT_DELETED
# │ wt_type_changed │ 0 │ #WT_TYPECHANGE
# │ wt_renamed │ 0 │ #WT_RENAMED
# │ ignored │ 0 │
# │ conflicts │ 0 │ #CONFLICTED
# │ ahead │ 0 │
# │ behind │ 0 │
# │ stashes │ 0 │
# │ branch │ main │
# │ remote │ upstream/main │
# ╰─────────────────────┴───────────────╯
def git_left_prompt [gs] {
# let gs = (gstat)
let os = ((sys).host.name)
# replace this 30 with whatever the width of the terminal is
let display_path = (path_abbrev_if_needed (home_abbrev $os) 30)
let branch_name = (get_branch_name $gs)
let ahead_cnt = (get_ahead_count $gs)
let behind_cnt = (get_behind_count $gs)
let index_change_cnt = (get_index_change_count $gs)
let wt_change_cnt = (get_working_tree_count $gs)
let conflicted_cnt = (get_conflicted_count $gs)
let untracked_cnt = (get_untracked_count $gs)
let has_no_changes = (
if ($index_change_cnt <= 0) &&
($wt_change_cnt <= 0) &&
($conflicted_cnt <= 0) &&
($untracked_cnt <= 0) {
$true
} else {
$false
}
)
# when reduce is available
# echo "one" "two" "three" | reduce { if ($acc | str starts-with 't') { $acc + $it } { $it }}
# some icons and the unicode char
# e0b0
# e0b1
# e0b2
# e0b3
# f1d3
# f07c or  f115
# f015 or  f7db
let GIT_BG = "#C4A000"
let GIT_FG = "#000000"
let TERM_BG = "#0C0C0C"
# The multi-color fg colors are good if you just have a black background
let AHEAD_ICON = (get_icon_by_name AHEAD_ICON)
# let A_COLOR = (ansi { fg:"#00ffff" bg: ($GIT_BG) })
let A_COLOR = (ansi { fg: ($GIT_FG) bg: ($GIT_BG) })
let BEHIND_ICON = (get_icon_by_name BEHIND_ICON)
# let B_COLOR = (ansi { fg:"#00ffff" bg: ($GIT_BG) })
let B_COLOR = (ansi { fg: ($GIT_FG) bg: ($GIT_BG) })
let INDEX_CHANGE_ICON = (get_icon_by_name INDEX_CHANGE_ICON)
# let I_COLOR = (ansi { fg:"#00ff00" bg: ($GIT_BG) })
let I_COLOR = (ansi { fg: ($GIT_FG) bg: ($GIT_BG) })
let CONFLICTED_CHANGE_ICON = (get_icon_by_name CONFLICTED_CHANGE_ICON)
# let C_COLOR = (ansi { fg:"#ff0000" bg: ($GIT_BG) })
let C_COLOR = (ansi { fg: ($GIT_FG) bg: ($GIT_BG) })
let WT_CHANGE_ICON = (get_icon_by_name WT_CHANGE_ICON)
# let W_COLOR = (ansi { fg:"#ff00ff" bg: ($GIT_BG) })
let W_COLOR = (ansi { fg: ($GIT_FG) bg: ($GIT_BG) })
let UNTRACKED_CHANGE_ICON = (get_icon_by_name UNTRACKED_CHANGE_ICON)
# let U_COLOR = (ansi { fg:"#ffff00" bg: ($GIT_BG) })
let U_COLOR = (ansi { fg: ($GIT_FG) bg: ($GIT_BG) })
let NO_CHANGE_ICON = (get_icon_by_name NO_CHANGE_ICON)
# let N_COLOR = (ansi { fg:"#00ff00" bg: ($GIT_BG) })
let N_COLOR = (ansi { fg: ($GIT_FG) bg: ($GIT_BG) })
let HAS_CHANGE_ICON = (get_icon_by_name HAS_CHANGE_ICON)
# let H_COLOR = (ansi { fg:"#ff0000" bg: ($GIT_BG) attr: b })
let H_COLOR = (ansi { fg: ($GIT_FG) bg: ($GIT_BG) attr: b })
let INSERT_SYMBOL_ICON = (get_icon_by_name INSERT_SYMBOL_ICON)
# let S_COLOR = (ansi { fg:"#00ffff" bg: ($GIT_BG) })
let S_COLOR = (ansi { fg: ($GIT_FG) bg: ($GIT_BG) })
let R = (ansi reset)
let repo_status = (
$"(
if ($ahead_cnt > 0) { $'($A_COLOR)($AHEAD_ICON)($ahead_cnt)($R)' }
)(
if ($behind_cnt > 0) { $'($B_COLOR)($BEHIND_ICON)($behind_cnt)($R)' }
)(
if ($index_change_cnt > 0) { $'($I_COLOR)($INDEX_CHANGE_ICON)($index_change_cnt)($R)' }
)(
if ($conflicted_cnt > 0) { $'($C_COLOR)($CONFLICTED_CHANGE_ICON)($conflicted_cnt)($R)' }
)(
if ($wt_change_cnt > 0) { $'($W_COLOR)($WT_CHANGE_ICON)($wt_change_cnt)($R)' }
)(
if ($untracked_cnt > 0) { $'($U_COLOR)($UNTRACKED_CHANGE_ICON)($untracked_cnt)($R)' }
)(
if ($has_no_changes == $true) { $'($N_COLOR)($NO_CHANGE_ICON)($R)' } else { $'($H_COLOR)($HAS_CHANGE_ICON)($R)' }
)"
)
# build segments and then put together the segments for the prompt
let os_segment = ([
(ansi { fg: "#080808" bg: "#CED7CF"}) # os bg color
(char space) # space
(get_os_icon $os) # os icon
(char space) # space
(ansi { fg: "#CED7CF" bg: "#3465A4"}) # color transition
(char -u e0b0) # 
(char space) # space
] | str collect)
let is_home_in_path = ($nu.cwd | str starts-with $nu.home-path)
let path_segment = (if (($is_home_in_path) && ($branch_name == "")) {
[
(char -u f015) #  home icon
(char space) # space
($display_path) # ~/src/forks/nushell
(ansi { fg: "#CED7CF" bg: "#3465A4"}) # color just to color the next space
(char space) # space
] | str collect
} else {
[
(char -u f07c) #  folder icon
(char space) # space
($display_path) # ~/src/forks/nushell
(ansi { fg: "#CED7CF" bg: "#3465A4"}) # color just to color the next space
(char space) # space
] | str collect
})
let git_segment = (if ($branch_name != "") {
[
(ansi { fg: "#3465A4" bg: "#4E9A06"}) # color
(char -u e0b0) # 
(char space) # space
(ansi { fg: ($TERM_BG) bg: "#4E9A06"}) # color
# (char -u f1d3) # 
(char -u e0a0) # 
(char space) # space
($branch_name) # main
(char space) # space
(ansi { fg: "#4E9A06" bg: ($GIT_BG)}) # color
(char -u e0b0) # 
(char space) # space
($R) # reset color
($repo_status) # repo status
] | str collect
})
let indicator_segment = (if ($branch_name == "") {
[
(ansi { fg: "#3465A4" bg: ($TERM_BG)}) # color
(char -u e0b0) # 
($R) # reset color
] | str collect
} else {
[
(ansi { fg: ($GIT_BG) bg: ($TERM_BG)}) # color
(char -u e0b0) # 
($R) # reset color
] | str collect
})
# assemble all segments for final prompt printing
[
($os_segment)
($path_segment)
($git_segment)
($indicator_segment)
] | str collect
}
def git_right_prompt [gs] {
let R = (ansi reset)
let TIME_BG = "#C4A000"
let TERM_FG = "#0C0C0C"
# let time_segment = ([
# (ansi { fg: ($TIME_BG) bg: ($TERM_FG)})
# (char -u e0b2) # 
# (ansi { fg: ($TERM_FG) bg: ($TIME_BG)})
# (char space)
# (date now | date format '%m/%d/%Y %I:%M:%S%.3f')
# (char space)
# ($R)
# ] | str collect)
# $time_segment
[
(ansi { fg: ($TIME_BG) bg: ($TERM_FG)})
(char -u e0b2) # 
(ansi { fg: ($TERM_FG) bg: ($TIME_BG)})
(char space)
(date now | date format '%m/%d/%Y %I:%M:%S%.3f')
(char space)
($R)
] | str collect
}
def git_prompt [] {
let gs = (gstat)
let left_prompt = (git_left_prompt $gs)
let right_prompt = (git_right_prompt $gs)
# return a table to be used kind of like a tuple
# so we don't have to run this script more than once per prompt
[
[name value];
[left_prompt ($left_prompt)]
[right_prompt ($right_prompt)]
]
#
# in the config.nu you would do something like
# let-env PROMPT_COMMAND = { git_prompt | where name == left_prompt }
# let-env PROMPT_COMMAND_RIGHT = { git_prompt | where name == right_prompt }
# let-env PROMPT_INDICATOR = " "
}
# fn repo_status(r: &Repository, detailed: bool) -> Option<String> {
# let mut out = vec![];
# if let Some(name) = get_head_shortname(r) {
# out.push(Cyan.paint(name));
# }
# if !detailed {
# if let Some((index_change, wt_change, conflicted, untracked)) = count_files_statuses(r) {
# if index_change != 0 || wt_change != 0 || conflicted != 0 || untracked != 0 {
# out.push(Red.bold().paint("*"));
# }
# }
# } else {
# if let Some((ahead, behind)) = get_ahead_behind(r) {
# if ahead > 0 {
# out.push(Cyan.paint(format!("↑{}", ahead)));
# }
# if behind > 0 {
# out.push(Cyan.paint(format!("↓{}", behind)));
# }
# }
# if let Some((index_change, wt_change, conflicted, untracked)) = count_files_statuses(r) {
# if index_change == 0 && wt_change == 0 && conflicted == 0 && untracked == 0 {
# out.push(Green.paint("✔"));
# } else {
# if index_change > 0 {
# out.push(Green.paint(format!("♦{}", index_change)));
# }
# if conflicted > 0 {
# out.push(Red.paint(format!("✖{}", conflicted)));
# }
# if wt_change > 0 {
# out.push(ANSIGenericString::from(format!("✚{}", wt_change)));
# }
# if untracked > 0 {
# out.push(ANSIGenericString::from("…"));
# }
# }
# }
# if let Some(action) = get_action(r) {
# out.push(Purple.paint(format!(" {}", action)));
# }
# }
# Some(ANSIStrings(&out).to_string())
# }
# pub fn display(sub_matches: &ArgMatches<'_>) {
# let my_path = env::current_dir().unwrap();
# let display_path = Blue.paint(shorten_path(my_path.to_str().unwrap()));
# let branch = match Repository::discover(my_path) {
# Ok(repo) => repo_status(&repo, sub_matches.is_present("git-detailed")),
# Err(_e) => None,
# };
# let display_branch = Cyan.paint(branch.unwrap_or_default());
# println!();
# println!("{} {}", display_path, display_branch);
# }
# Abbreviate home path
def home_abbrev [] {
let is_home_in_path = ($nu.cwd | str starts-with $nu.home-path)
if ($is_home_in_path == $true) {
let lin-home = ($nu.home-path | str find-replace -a '\\' '/' | str downcase)
let lin-pwd = ($nu.cwd | str find-replace -a '\\' '/' | str downcase)
$lin-pwd | str find-replace $lin-home '~'
} else {
$nu.cwd | str downcase
}
}
let AHEAD_ICON = "↑"
let BEHIND_ICON = "↓"
let NO_CHANGES_ICON = "✔" # Green
let INDEX_CHANGE_ICON = "♦" # Green
let WT_CHANGE_ICON = "✚"
let CONFLICTED_CHANGES_ICON = "✖" # Red
let UNTRACKED_CHANGES_ICON = "…"
let INSERT_SYMBOL_ICON = "❯"
# ╭─────────────────────┬───────────────╮
# │ idx_added_staged │ 0 │ #INDEX_NEW
# │ idx_modified_staged │ 0 │ #INDEX_MODIFIED
# │ idx_deleted_staged │ 0 │ #INDEX_DELETED
# │ idx_renamed │ 0 │ #INDEX_RENAMED
# │ idx_type_changed │ 0 │ #INDEX_TYPECHANGE
# │ wt_untracked │ 0 │ #WT_NEW
# │ wt_modified │ 0 │ #WT_MODIFIED
# │ wt_deleted │ 0 │ #WT_DELETED
# │ wt_type_changed │ 0 │ #WT_TYPECHANGE
# │ wt_renamed │ 0 │ #WT_RENAMED
# │ ignored │ 0 │
# │ conflicts │ 0 │ #CONFLICTED
# │ ahead │ 0 │
# │ behind │ 0 │
# │ stashes │ 0 │
# │ branch │ main │
# │ remote │ upstream/main │
# ╰─────────────────────┴───────────────╯
# (index_change, wt_change, conflicted, untracked)) = count_files_statuses(r) {
let gs = (gstat)
def get_index_changes [] {
let index_new = ($gs | get idx_added_staged)
let index_modified = ($gs | get idx_modified_staged)
let index_deleted = ($gs | get idx_deleted_staged)
let index_renamed = ($gs | get idx_renamed)
let index_typechanged = ($gs | get idx_type_changed)
$index_new + $index_modified + $index_deleted + $index_renamed + $index_typechanged
}
def get_working_tree_changes [] {
let wt_modified = ($gs | get wt_modified)
let wt_deleted = ($gs | get wt_deleted)
let wt_typechanged = ($gs | get wt_type_changed)
let wt_renamed = ($gs | get wt_renamed)
$wt_modified + $wt_deleted + $wt_typechanged + $wt_renamed
}
def get_conflicted [] {
($gs | get conflicts)
}
def get_untracked [] {
($gs | get wt_untracked)
}
def repo_status [] {
let branch = ($gs | get branch) # Cyan
let ahead = ($gs | get ahead) # Cyan
let behind = ($gs | get behind)
let index_changed = (get_index_changes)
let wt_changed = (get_working_tree_changes)
let conflicted = (get_conflicted)
let untracked = (get_untracked)
if $ahead > 0 {
echo "ahead > 0"
$"($AHEAD_ICON)($ahead)" # Cyan
}
if $behind > 0 {
echo "behind > 0"
$"($BEHIND_ICON)($behind)" # Cyan
}
if ($index_changed == 0) && ($wt_changed == 0) && ($conflicted == 0) && ($untracked == 0) {
echo "all clean"
$"($NO_CHANGES_ICON)" # Green
} else {
if $index_changed > 0 {
echo "index changed > 0"
$"($INDEX_CHANGE_ICON)($index_changed)" # Green
}
if $conflicted > 0 {
echo "conflicted > 0"
$"($CONFLICTED_CHANGES_ICON)($conflicted)" # Red
}
if $wt_changed > 0 {
echo "wt_changed > 0"
$"($WT_CHANGE_ICON)($wt_changed)"
}
if $untracked > 0 {
echo "untracked > 0"
$"($UNTRACKED_CHANGES_ICON)($untracked)"
}
}
}
let display_path = (home_abbrev) # Blue
let branch = ($gs | get branch) # Cyan
let repo = (repo_status)
$"(ansi gb)($display_path)(ansi reset)(char lparen)(ansi cyan)($branch)(ansi reset)(char rparen) (ansi yellow)[($repo)](ansi reset) >"
# Code generated by zoxide. DO NOT EDIT.
# =============================================================================
#
# Utility functions for zoxide.
#
# Default prompt for Nushell.
def __zoxide_prompt [] {
# if gstat plugin is installed could do `gstat | get branch`
let git = $'(do -i {git rev-parse --abbrev-ref HEAD} | decode utf-8 | str trim -r -c (char nl))'
let git = (if ($git | str length) == 0 { '' } else {
build-string (char lp) (ansi cb) $git (ansi reset) (char rp)
})
build-string (ansi gb) ($nu.cwd) (ansi reset) $git '> '
}
# =============================================================================
#
# Hook configuration for zoxide.
#
# Hook to add new entries to the database.
def __zoxide_hook [] {
# shells | where active == $true | get path | each {
# zoxide add -- $it
# }
zoxide add -- (shells | where active == $true | get path | get 0)
}
# Initialize hook.
# TODO: PROMPT_COMMAND_RIGHT should probably be referenced somewhere
# prompts are blocks now
# let-env PROMPT_COMMAND = { (
# if ("PROMPT_COMMAND" not-in (env).name) {
# $'__zoxide_hook;__zoxide_prompt'
# } else {
# $'__zoxide_hook;(do $env.PROMPT_COMMAND)'
# }
# ) }
let-env _OLD_PROMPT_COMMAND = $env.PROMPT_COMMAND
let-env PROMPT_COMMAND = {
__zoxide_hook # gets executed in both cases
if ("PROMPT_COMMAND" not-in (env).name) {
__zoxide_prompt # run default prompt
} else {
do $env._OLD_PROMPT_COMMAND # run the original prompt
}
}
# Initialize hook.
# let-env PROMPT_COMMAND = (
# let prompt = (if ("PROMPT_COMMAND" not-in (env).name) {
# if ($nu.config | select prompt | empty?) {
# '__zoxide_prompt'
# } else {
# $nu.config.prompt
# }
# } else {
# $nu.env.PROMPT_COMMAND
# });
# if ($prompt | str contains '__zoxide_hook') { $prompt } else { $'__zoxide_hook;($prompt)' }
# )
# =============================================================================
#
# When using zoxide with --no-aliases, alias these internal functions as
# desired.
#
# Jump to a directory using only keywords.
def __zoxide_z [...rest:string] {
# if (shells | where active == $true) {
# if ($rest | length) > 1 {
# $'zoxide: can only jump in active shells(char nl)'
# } else {
# cd $rest
# }
# } else {
# let arg0 = ($rest | append '~' | first 1)
# if ($rest | length) <= 1 && ($arg0 == '-' || ($arg0 | path expand | path exists)) {
# cd $arg0
# } else {
cd $'(zoxide query --exclude ($nu.cwd) -- $rest | decode utf-8 | str trim -r -c (char nl))'
# }
# }
}
# Jump to a directory using interactive search.
def __zoxide_zi [...rest:string] {
# if (shells | where active == $false) {
# $'zoxide: can only jump in active shells(char nl)'
# } else {
cd $'(zoxide query -i -- $rest | decode utf-8 | str trim -r c (char nl))'
# }
}
# =============================================================================
#
# Convenient aliases for zoxide. Disable these using --no-aliases.
#
alias z = __zoxide_z
alias zi = __zoxide_zi
# =============================================================================
#
# To initialize zoxide, add this to your configuration (find it by running
# `config path` in Nushell):
#
# startup = ['zoxide init nushell --hook prompt | save ~/.zoxide.nu', 'source ~/.zoxide.nu']
#
# Note: zoxide only supports Nushell v0.37.0 and above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment