summaryrefslogtreecommitdiff
path: root/nushell/config.nu
blob: 8bdf6c7d7df8146722e322eadcab9d9d0e83beee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
$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 mvn = mvn -gs .config/maven/settings.xml
alias wtr = weather
alias nuconf = config nu
alias nuenv = config env
alias ssh = ghostty +ssh

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