nushell config

This commit is contained in:
2026-01-30 16:48:11 +08:00
parent 165681a18e
commit 05b2a28b94
10 changed files with 246 additions and 56 deletions

View File

@@ -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

View File

View File

@@ -1,9 +0,0 @@
use pj_starship.nu
use pj_zoxide.nu
export def --env init [] {
# zoxide
pj_zoxide init
# starship
pj_starship init
}

View File

@@ -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

83
nushell/modules/pj_fzf.nu Normal file
View File

@@ -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
]
}
}

View File

@@ -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_(?<name>.*).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")
}
}

View File

@@ -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
}

View File

@@ -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+.

View File

@@ -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 *

View File

@@ -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