Last active
June 9, 2023 20:44
-
-
Save skelly37/5b23a80b7c9b8fa62660145b62253a99 to your computer and use it in GitHub Desktop.
Nu simple functions and prompt
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
let-env CDPATH = ["." "/home/skelly37" $env.HOME "/home/skelly37/.config" "/home/skelly37/it" "/" ] | |
# SOURCES | |
# they all come from https://github.com/nushell/nu_scripts | |
source /home/skelly37/.config/nushell/external/dict.nu | |
source /home/skelly37/.config/nushell/external/wolframalpha.nu | |
source /home/skelly37/.config/nushell/external/math_functions.nu | |
source /home/skelly37/.config/nushell/external/ultimate_extractor.nu | |
source /home/skelly37/.config/nushell/external/cdpath.nu | |
source /home/skelly37/.config/nushell/external/run-c.nu | |
source /home/skelly37/.config/nushell/external/up.nu | |
source /home/skelly37/.config/nushell/external/git_completions.nu | |
# ALIASES | |
alias l = ls | |
alias la = ls -a | |
alias d = ls -d | |
alias n = clear | |
alias pe = sudo poweroff | |
alias chx = chmod a+x | |
# https://gist.github.com/skelly37/43747936edba57c907ae2ccd08d93943 | |
alias python = python3 -i /home/skelly37/pyshutils.py | |
# CUSTOM FUNCTIONS | |
# see: pre-commit.com | |
def column [n] { transpose | select $n | transpose | select column1 | headers } | |
def update_nu [] {cargo install nu; cargo install nu_plugin_query; register /home/skelly37/.cargo/bin/nu_plugin_query} | |
# I love this one https://github.com/volitank/nala | |
def upgrade [] {sudo nala upgrade; flatpak update} | |
# prompt displaying git status in yellow brackets (if appliable), then red (root/admin) or default green path prompt | |
def create_left_prompt [] { | |
let git_branch = (do -i {git branch --show-current | each {str trim} | str collect}) | |
mut git_status = (do -i {git status -s|lines -s|str trim|split column ' '|get column1}) | |
if not ($git_status | is-empty) { | |
$git_status = ($git_status | uniq -c | format '{value}:{count}' | str collect ' ') | |
} | |
let git_segment = ((if ($git_branch|is-empty) {""} else {["(" ($git_branch)] | str collect})) | |
let git_segment = if ($git_status|is-empty) {[$git_segment ") "] | str collect} else {[$git_segment " " $git_status ") "] | str collect} | |
let git_segment = if (($git_segment | str trim) == ")") {""} else {$"(ansi yellow_bold)($git_segment)"} | |
let path_segment = if (is-admin) { | |
$"(ansi red_bold)($env.PWD)" | |
} else { | |
$"(ansi green_bold)($env.PWD)" | |
} | |
($"($git_segment)($path_segment)" | str trim) | |
} | |
let-env PROMPT_COMMAND = { || create_left_prompt } | |
let-env PROMPT_COMMAND_RIGHT = { || } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment