From 05b2a28b94f861128efa5e97a1a6a380de997e0b Mon Sep 17 00:00:00 2001 From: gwbeip Date: Fri, 30 Jan 2026 16:48:11 +0800 Subject: [PATCH] nushell config --- nushell/aliases/pj_aliases.nu | 19 -------- nushell/cache/.gitkeep | 0 nushell/modules/pj.nu | 9 ---- nushell/modules/pj_aliases.nu | 21 +++++++++ nushell/modules/pj_fzf.nu | 83 ++++++++++++++++++++++++++++++++ nushell/modules/pj_prompt.nu | 56 ++++++++++++++++++++++ nushell/modules/pj_starship.nu | 11 ----- nushell/modules/pj_zoxide.nu | 86 +++++++++++++++++++++++++++++++--- nushell/nu_polyjuice.nu | 14 ++---- zsh/zshenv | 3 +- 10 files changed, 246 insertions(+), 56 deletions(-) delete mode 100644 nushell/aliases/pj_aliases.nu delete mode 100644 nushell/cache/.gitkeep delete mode 100644 nushell/modules/pj.nu create mode 100644 nushell/modules/pj_aliases.nu create mode 100644 nushell/modules/pj_fzf.nu create mode 100644 nushell/modules/pj_prompt.nu delete mode 100644 nushell/modules/pj_starship.nu diff --git a/nushell/aliases/pj_aliases.nu b/nushell/aliases/pj_aliases.nu deleted file mode 100644 index fc87197..0000000 --- a/nushell/aliases/pj_aliases.nu +++ /dev/null @@ -1,19 +0,0 @@ -alias l = ls -alias ll = ls -l -alias la = ls -a -alias lla = ls -la -alias lh = ls -lh -alias lt = ls -l | sort-by modified | reverse - -alias cdi = cd (ls **/ | get name | str join "\n" | fzf) - -if $env.OS == "Windows_NT" { - -} else { - alias py = python3 -} - -alias weather = curl wttr.in -alias moon = curl wttr.in/Moon -alias quote = curl https://api.quotable.io/random | from json | get content -alias dadjoke = curl -H "Accept: application/json" https://icanhazdadjoke.com/ | from json | get joke diff --git a/nushell/cache/.gitkeep b/nushell/cache/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/nushell/modules/pj.nu b/nushell/modules/pj.nu deleted file mode 100644 index b514753..0000000 --- a/nushell/modules/pj.nu +++ /dev/null @@ -1,9 +0,0 @@ -use pj_starship.nu -use pj_zoxide.nu - -export def --env init [] { - # zoxide - pj_zoxide init - # starship - pj_starship init -} diff --git a/nushell/modules/pj_aliases.nu b/nushell/modules/pj_aliases.nu new file mode 100644 index 0000000..d90b160 --- /dev/null +++ b/nushell/modules/pj_aliases.nu @@ -0,0 +1,21 @@ +export alias l = ls +export alias ll = ls -l +export alias la = ls -a +export alias lla = ls -la +export alias lh = ls -lh +export alias lt = ls -l | sort-by modified | reverse + +export alias cdi = cd (ls **/ | get name | str join "\n" | fzf) + +export def py [...rest: string] { + if (which ^py | is-not-empty) { + ^py ...$rest + } else { + ^python3 ...$rest + } +} + +export alias weather = curl wttr.in +export alias moon = curl wttr.in/Moon +export alias quote = curl https://api.quotable.io/random | from json | get content +export alias dadjoke = curl -H "Accept: application/json" https://icanhazdadjoke.com/ | from json | get joke diff --git a/nushell/modules/pj_fzf.nu b/nushell/modules/pj_fzf.nu new file mode 100644 index 0000000..7c8f3f9 --- /dev/null +++ b/nushell/modules/pj_fzf.nu @@ -0,0 +1,83 @@ +# History +const fzf_history_selector = { + name: fzf_history_selector + modifier: alt + keycode: char_h + mode: [emacs, vi_insert, vi_normal] + event: [ + { + send: executehostcommand + cmd: " + let result = history + | reverse + | get command + | str replace --all (char newline) ' ' + | to text + | fzf --height 40% --reverse --border; + commandline edit --append $result; + commandline set-cursor --end + " + } + ] +} + +const fzf_file_selector = { + name: fzf_file_selector + modifier: alt + keycode: char_f + mode: [emacs, vi_insert, vi_normal] + event: [ + { + send: executehostcommand + cmd: " + let result = (ls **/* | where type == 'file' | get name | to text | fzf --height 40% --reverse --border); + commandline edit --append $result; + commandline set-cursor --end + " + } + ] +} + +const fzf_dir_selector = { + name: fzf_dir_selector + modifier: alt + keycode: char_d + mode: [emacs, vi_insert, vi_normal] + event: [ + { + send: executehostcommand + cmd: " + let result = (ls **/ | where type == 'dir' | get name | to text | fzf --height 40% --reverse --border); + commandline edit --append $result; + commandline set-cursor --end + " + } + ] +} + +# Update the $env.config +export-env { + # Only append if not already present (check by name) + let has_history_menu = $env.config.keybindings | any {|kb| $kb.name == "fzf_history_selector"} + if not $has_history_menu { + $env.config.keybindings = $env.config.keybindings | append [ + $fzf_history_selector + ] + } + + # Only append if not already present (check by name) + let has_fzf_file_selector = $env.config.keybindings | any {|kb| $kb.name == "fzf_file_selector"} + if not $has_fzf_file_selector { + $env.config.keybindings = $env.config.keybindings | append [ + $fzf_file_selector + ] + } + + # Only append if not already present (check by name) + let has_fzf_dir_selector = $env.config.keybindings | any {|kb| $kb.name == "fzf_dir_selector"} + if not $has_fzf_dir_selector { + $env.config.keybindings = $env.config.keybindings | append [ + $fzf_dir_selector + ] + } +} diff --git a/nushell/modules/pj_prompt.nu b/nushell/modules/pj_prompt.nu new file mode 100644 index 0000000..af2497e --- /dev/null +++ b/nushell/modules/pj_prompt.nu @@ -0,0 +1,56 @@ +export def --env "pj starship config" [name: string] { + if (which ^starship | is-empty) { + echo "starship is not installed." | warn + return + } + $env.starship_config = ($env.NU_POLYJUICE_PATH | path join ".." "starship" $"starship_($name).toml") +} + +export def --env "pj starship list" [] { + if (which ^starship | is-empty) { + echo "starship is not installed." | warn + return + } + ls ($env.NU_POLYJUICE_PATH | path join ".." "starship") -s | get name | parse -r '^(starship_(?.*).toml)$' | get name +} + +export-env { + if (which ^starship | is-not-empty) { + $env.STARSHIP_SHELL = "nu" + load-env { + STARSHIP_SESSION_KEY: (random chars -l 16) + PROMPT_MULTILINE_INDICATOR: ( + ^'starship' prompt --continuation + ) + + # Does not play well with default character module. + # TODO: Also Use starship vi mode indicators? + PROMPT_INDICATOR: "" + + PROMPT_COMMAND: {|| + # jobs are not supported + ( + ^'starship' prompt + --cmd-duration $env.CMD_DURATION_MS + $"--status=($env.LAST_EXIT_CODE)" + --terminal-width (term size).columns + ) + } + + config: ($env.config? | default {} | merge { + render_right_prompt_on_last_line: true + }) + + PROMPT_COMMAND_RIGHT: {|| + ( + ^'starship' prompt + --right + --cmd-duration $env.CMD_DURATION_MS + $"--status=($env.LAST_EXIT_CODE)" + --terminal-width (term size).columns + ) + } + } + $env.starship_config = ($env.NU_POLYJUICE_PATH | path join ".." "starship" $"starship_default.toml") + } +} diff --git a/nushell/modules/pj_starship.nu b/nushell/modules/pj_starship.nu deleted file mode 100644 index 0280771..0000000 --- a/nushell/modules/pj_starship.nu +++ /dev/null @@ -1,11 +0,0 @@ -export def --env config [name: string] { - $env.starship_config = ($env.NU_POLYJUICE_PATH | path join ".." "starship" $"starship_($name).toml") -} - -export def --env init [] { - let starship_nushell_path = ($env.NU_POLYJUICE_AUTOLOAD_DIRS | path join "starship.nu") - if ($starship_nushell_path | path exists) { - rm $starship_nushell_path - } - starship init nu | save -f $starship_nushell_path -} diff --git a/nushell/modules/pj_zoxide.nu b/nushell/modules/pj_zoxide.nu index f8d728b..7673acb 100644 --- a/nushell/modules/pj_zoxide.nu +++ b/nushell/modules/pj_zoxide.nu @@ -1,7 +1,81 @@ -export def --env init [] { - let zoxide_nushell_path = ($env.NU_POLYJUICE_AUTOLOAD_DIRS | path join "zoxide.nu") - if ($zoxide_nushell_path | path exists) { - rm $zoxide_nushell_path - } - zoxide init nushell --cmd z | save -f $zoxide_nushell_path +# export def --env init [] { +# let zoxide_nushell_path = ($env.NU_POLYJUICE_AUTOLOAD_DIRS | path join "zoxide.nu") +# if ($zoxide_nushell_path | path exists) { +# rm $zoxide_nushell_path +# } +# zoxide init nushell --cmd z | save -f $zoxide_nushell_path +# } + + + + +# Code generated by zoxide. DO NOT EDIT. + +# ============================================================================= +# +# Hook configuration for zoxide. +# + +# Initialize hook to add new entries to the database. +export-env { + $env.config = ( + $env.config? + | default {} + | upsert hooks { default {} } + | upsert hooks.env_change { default {} } + | upsert hooks.env_change.PWD { default [] } + ) + let __zoxide_hooked = ( + $env.config.hooks.env_change.PWD | any { try { get __zoxide_hook } catch { false } } + ) + if not $__zoxide_hooked { + $env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD | append { + __zoxide_hook: true, + code: {|_, dir| zoxide add -- $dir} + }) + } } + +# ============================================================================= +# +# When using zoxide with --no-cmd, alias these internal functions as desired. +# + +# Jump to a directory using only keywords. +def --env --wrapped __zoxide_z [...rest: string] { + let path = match $rest { + [] => {'~'}, + [ '-' ] => {'-'}, + [ $arg ] if ($arg | path expand | path type) == 'dir' => {$arg} + _ => { + zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n" + } + } + cd $path +} + +# Jump to a directory using interactive search. +def --env --wrapped __zoxide_zi [...rest:string] { + cd $'(zoxide query --interactive -- ...$rest | str trim -r -c "\n")' +} + +# ============================================================================= +# +# Commands for zoxide. Disable these using --no-cmd. +# + +export alias z = __zoxide_z +export alias zi = __zoxide_zi + +# ============================================================================= +# +# Add this to your env file (find it by running `$nu.env-path` in Nushell): +# +# zoxide init nushell | save -f ~/.zoxide.nu +# +# Now, add this to the end of your config file (find it by running +# `$nu.config-path` in Nushell): +# +# source ~/.zoxide.nu +# +# Note: zoxide only supports Nushell v0.89.0+. diff --git a/nushell/nu_polyjuice.nu b/nushell/nu_polyjuice.nu index 8be4f45..5bf0b57 100644 --- a/nushell/nu_polyjuice.nu +++ b/nushell/nu_polyjuice.nu @@ -3,15 +3,9 @@ $env.config.show_banner = false # Terminal Polyjuice Files's Path $env.NU_POLYJUICE_PATH = $env.FILE_PWD -$env.NU_POLYJUICE_CACHE_PATH = $env.NU_POLYJUICE_PATH + "/cache" -$env.NU_POLYJUICE_AUTOLOAD_DIRS = ($nu.user-autoload-dirs) # modules -use modules/pj.nu -use modules/pj_starship.nu -use modules/pj_zoxide.nu - -source aliases/pj_aliases.nu - -# starship -pj_starship config "default" +use modules/pj_aliases.nu * +use modules/pj_fzf.nu * +use modules/pj_zoxide.nu * +use modules/pj_prompt.nu * diff --git a/zsh/zshenv b/zsh/zshenv index f8e91d7..cd317cb 100644 --- a/zsh/zshenv +++ b/zsh/zshenv @@ -1,6 +1,7 @@ # "[interop] appendWindowsPath=false" in /etc/wsl.conf is setted # Append VSCode on Windows into PATH so that vscode can be used in WSL export PATH=$PATH:'/mnt/c/Users/gwbei/AppData/Local/Programs/Microsoft VS Code/bin/' +export PATH=$PATH:'/mnt/c/Users/gwbei/AppData/Local/Programs/Zed/bin/zed' # Language and encoding related -export LC_ALL=C.UTF-8 \ No newline at end of file +export LC_ALL=C.UTF-8