Last active
May 3, 2022 14:36
-
-
Save zachjamesgreen/c666cbfe329f9a85c7a2d8b132316951 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # 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