summaryrefslogtreecommitdiff
path: root/nushell/config.nu
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-09-26 19:44:48 +0800
committereltrac <hi@eltr.ac>2026-09-26 19:44:48 +0800
commitf2c93c07dbdd4eb894ab65f75b760bc895215823 (patch)
tree151e522055a71543e809fe8a02d65391cf43c150 /nushell/config.nu
parent015911736d12da19fd168360840c025f22f56696 (diff)
nushell: add nushell configuration
Diffstat (limited to 'nushell/config.nu')
-rw-r--r--nushell/config.nu126
1 files changed, 126 insertions, 0 deletions
diff --git a/nushell/config.nu b/nushell/config.nu
new file mode 100644
index 0000000..0475a0e
--- /dev/null
+++ b/nushell/config.nu
@@ -0,0 +1,126 @@
+$env.config.buffer_editor = 'nvim'
+$env.config.show_banner = false
+
+# ---- Aliases ----
+alias vim = nvim
+alias vi = nvim
+alias eml = aerc
+alias tinypng = tinifier
+alias lg = lazygit
+alias rm = trash
+alias you-get = you-get --cookies ~/.local/share/you-get/www.bilibili.com_cookies.txt
+alias fjc = fj --host codeberg.org
+alias fjs = fj --host src.eltr.ac
+alias plantuml = java -jar ~/.local/jar/plantuml.jar
+alias hugo-tag = uv run ~/Projects/snippets/hugo-tag-wrangler/script.py
+alias vimulti = bb ~/Projects/vimulti/vimulti.clj
+alias nvimj = vimulti java-edition
+alias switch-proxy = bb ~/Projects/snippets/QoL/switch-proxy.clj
+alias swp = switch-proxy
+alias wtr = weather
+alias nuconf = config nu
+alias nuenv = config env
+
+# ---- Custom commands ----
+
+# Remind to use mosh instead of ssh
+def ssh [...rest: string] {
+ print "⚠️ You should use mosh!"
+ ^ssh ...$rest
+}
+
+# cd into one dir and list its content
+def peek [...paths: path] {
+ if ($paths | is-empty) {
+ print $"📂 Subdirectories of ($env.PWD):"
+ ls | where type == dir | get name | print
+ } else {
+ for dir in $paths {
+ if ($dir | path type) == dir {
+ print $"📁 ($dir):"
+ facad $dir
+ print ""
+ } else {
+ print $"peek: '($dir)' is not a directory"
+ }
+ }
+ }
+}
+
+# mkdir and cd
+def --env mkcd [dir: path] {
+ mkdir $dir
+ cd $dir
+}
+
+# cd ../
+def --env back [] {
+ cd ..
+}
+
+# git visualization
+def gitvis [] {
+ git log --oneline --graph --all --decorate
+}
+
+# check what apps are not managed by homebrew
+def brewoutcasts [] {
+ let apps = (ls /Applications | where type == dir and name ends-with '.app')
+ let total = ($apps | length)
+ let formulae = (brew list --formula | str trim)
+ let casks = (brew list --cask | str trim)
+ mut unmanaged = []
+ for app in $apps {
+ let name = ($app.name | str replace -r '\.app$' '')
+ let base = ($name | str lowercase)
+ let normalized = (match $base {
+ 'hidden bar' => 'hiddenbar'
+ 'helium' => 'helium-browser'
+ _ => ($base | str replace -a ' ' '-' | str replace -a '.' '-')
+ })
+ if $base == 'safari' { continue }
+ let managed = ($formulae | any {|f| ($f | str lowercase) == $normalized }) or ($casks | any {|c| ($c | str lowercase) == $normalized })
+ if (not $managed) {
+ print $"\n($name) is NOT managed by Homebrew"
+ print $"-- Searching Homebrew for ($name)..."
+ brew search $normalized | print
+ $unmanaged = ($unmanaged | append $name)
+ }
+ }
+ print ""
+ print $"-- Summary: ($unmanaged | length) out of ($total) applications are not managed by Homebrew"
+}
+
+# yazi: cd into the dir yazi was closed in
+def --env y [...args: string] {
+ let tmp = (mktemp -t 'yazi-cwd.XXXXXX' | str trim)
+ command yazi ...$args --cwd-file=$tmp
+ let cwd = (open --raw $tmp | str trim)
+ if ($cwd | is-not-empty) and ($cwd != $env.PWD) { cd $cwd }
+ rm -f $tmp
+}
+
+def weather [] {
+ curl wttr.in/Shapingba
+}
+
+# thefuck is a bash/zsh hook; nu shim shows the suggested fix
+def fuck [] {
+ let last = (history | get command | str trim | last)
+ thefuck $last
+}
+
+# ---- Startup side effects ----
+try { ^ssh-add ~/.ssh/id_ed25519_git o+e>| null } catch { }
+
+# ---- zoxide ----
+if (which zoxide | is-not-empty) {
+ mkdir ~/.config/nushell/autoload
+ zoxide init nushell | save -f ~/.config/nushell/autoload/zoxide.nu
+}
+
+# ---- mise ----
+if (which mise | is-not-empty) {
+ mkdir ~/.config/nushell/autoload
+ mise activate nu | str replace -a 'str upcase' 'str uppercase' | save -f ~/.config/nushell/autoload/mise.nu
+}