Skip to content

Instantly share code, notes, and snippets.

@zachjamesgreen
Last active May 3, 2022 14:36
Show Gist options
  • Save zachjamesgreen/c666cbfe329f9a85c7a2d8b132316951 to your computer and use it in GitHub Desktop.
Save zachjamesgreen/c666cbfe329f9a85c7a2d8b132316951 to your computer and use it in GitHub Desktop.
# Nushell Environment Config File
def create_left_prompt [] {
let $prompt = ([
(ansi green),
(whoami | str trim),
(ansi blue),
'@',
(ansi cyan),
(hostname | str trim),
(_get_prompt_path),
(ansi reset)
] | str collect)
$prompt
}
def _get_prompt_path [] {
let path_segment = ($env.PWD)
let home = ($env.HOME)
let is_home = if ($path_segment == $home) {' ~'} else {' ' + $path_segment}
([(ansi yellow) $is_home] | str collect)
}
def create_right_prompt [] {
let time_segment = ([
(date now | date format '%m/%d/%Y %r')
] | str collect)
$time_segment
}
def _is_git_dir [] {
let git_dir = (ls -a | where name == .git | length)
let res = if $git_dir > 0 {true} else {false}
$res
}
def git_current_branch [] {
let current_branch = (git symbolic-ref --quiet HEAD | split column "/" a c branch | get branch | str collect | str trim)
$current_branch
}
def add_git_info [] {
let git_info = if _is_git_dir {build-string (ansi green) '[' (ansi blue) (git_current_branch) (ansi green) ']'} else {''}
$git_info
}
def random_emoji [] {
let emojis = [
๐Ÿ’ฝ ๐Ÿฆ„ ๐Ÿถ ๐Ÿฑ ๐Ÿญ
๐Ÿฐ ๐Ÿป ๐Ÿ’ฃ ๐Ÿ“ท ๐Ÿ“ธ
๐ŸŽฅ ๐ŸŽž๏ธ ๐Ÿ“ฝ๏ธ ๐Ÿงฎ ๐Ÿ“€
๐Ÿ’ฟ ๐Ÿ’พ ๐Ÿ“• ๐Ÿ“– ๐Ÿ“—
๐Ÿ“˜ ๐Ÿ“™ ๐Ÿ“ˆ ๐Ÿ“‰ ๐Ÿ”‘
๐Ÿ—๏ธ ๐Ÿ”จ ๐Ÿช“ โ›๏ธ โš’๏ธ
๐Ÿ› ๏ธ ๐Ÿ—ก๏ธ โš”๏ธ ๐Ÿ”ซ ๐Ÿšฌ
๐Ÿช’ ๐Ÿ’ก ๐Ÿ”Œ ๐Ÿ”‹ ๐Ÿ”Œ
]
$emojis | get (random integer ..(($emojis | length) - 1))
}
# Use nushell functions to define your right and left prompt
let-env PROMPT_COMMAND = { build-string (create_left_prompt) ' ' (add_git_info) "\n" }
# let-env PROMPT_COMMAND_RIGHT = { create_right_prompt }
# The prompt indicators are environmental variables that represent
# the state of the prompt
let-env PROMPT_INDICATOR = { build-string (ansi reset) "\n" (random_emoji) "ใ€‰" }
let-env PROMPT_INDICATOR_VI_INSERT = { ": " }
let-env PROMPT_INDICATOR_VI_NORMAL = { "ใ€‰" }
let-env PROMPT_MULTILINE_INDICATOR = { "::: " }
# Specifies how environment variables are:
# - converted from a string to a value on Nushell startup (from_string)
# - converted from a value back to a string when running external commands (to_string)
# Note: The conversions happen *after* config.nu is loaded
let-env ENV_CONVERSIONS = {
"PATH": {
from_string: { |s| $s | split row (char esep) }
to_string: { |v| $v | str collect (char esep) }
}
"Path": {
from_string: { |s| $s | split row (char esep) }
to_string: { |v| $v | str collect (char esep) }
}
}
# Directories to search for scripts when calling source or use
#
# By default, <nushell-config-dir>/scripts is added
let-env NU_LIB_DIRS = [
($nu.config-path | path dirname | path join 'scripts')
]
# Directories to search for plugin binaries when calling register
#
# By default, <nushell-config-dir>/plugins is added
let-env NU_PLUGIN_DIRS = [
($nu.config-path | path dirname | path join 'plugins')
]
# To add entries to PATH (on Windows you might use Path), you can use the following pattern:
# let-env PATH = ($env.PATH | prepend '/some/path')
let-env PATH = ($env.PATH | append '/home/zach/bin/node-v16.14.0-linux-x64/bin')
alias ggpull = (git pull origin (git_current_branch))
alias ggpush = (^git push origin (git_current_branch))
alias gst = (git status | str collect)
def calldb [query] {
psql lts -U ltflask -h localhost -p 6432 --csv -c $query | from csv
}
def start_agent [] {
echo "Starting ssh-agent"
let vars = (ssh-agent -c | lines | first 2 | parse "setenv {name} {value};" | reduce -f {} { |it, acc| $acc | upsert $it.name $it.value })
$vars
}
start_agent | load-env
ssh-add ~/.ssh/work_git
def q [] {
echo "Quiting"
kill -9 ($env.SSH_AGENT_PID | into int)
exit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment