Skip to content

Commit a0f578a

Browse files
committed
added more stuff to nushell.
zoxide and starship are now optional, but fish is needed for completions.
1 parent 586cae9 commit a0f578a

File tree

9 files changed

+1284
-36
lines changed

9 files changed

+1284
-36
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ wget-log*
1111
lazy-lock.json
1212
#nushell history
1313
history.sqlite3*
14+
history.txt

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ For telescope:
8888
* nvim ($EDITOR and $VISUAL is set to this)
8989
* less
9090
* fzf
91-
* optional: zoxide (nicer cd. mandatory for nushell)
92-
* optional: starship (nice prompt. mandatory for nushell)
91+
* optional: zoxide (nicer cd)
92+
* optional: starship (nice prompt)
9393

9494
Software used by aliases:
9595
* nvim
@@ -101,6 +101,10 @@ Software used by aliases:
101101
* libreoffice (for word to pdf conversions)
102102
* sshfs
103103

104+
### nushell
105+
106+
Nushell currently also needs fish installed for comlpletions.
107+
104108
### Paru
105109
uses yazi as a file explorer
106110

nushell/.config/nushell/config.nu

+39-26
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,27 @@ let light_theme = {
136136
shape_vardecl: purple
137137
}
138138

139-
# External completer example
140-
# let carapace_completer = {|spans|
141-
# carapace $spans.0 nushell ...$spans | from json
142-
# }
139+
let fish_completer = {|spans|
140+
fish --command $'complete "--do-complete=($spans | str join " ")"'
141+
| $"value(char tab)description(char newline)" + $in
142+
| from tsv --flexible --no-infer
143+
}
144+
145+
let carapace_completer = {|spans: list<string>|
146+
carapace $spans.0 nushell ...$spans
147+
| from json
148+
| if ($in | default [] | where value =~ '^-.*ERR$' | is-empty) { $in } else { null }
149+
}
150+
151+
let zoxide_completer = {|spans|
152+
$spans | skip 1 | zoxide query -l $in | lines | where {|x| $x != $env.PWD}
153+
}
143154

155+
# This completer will use carapace by default
156+
let external_completer = $fish_completer
144157
# The default config record. This is where much of your global configuration is setup.
145158
$env.config = {
146-
show_banner: false # true or false to enable or disable the welcome banner at startup
159+
show_banner: true # true or false to enable or disable the welcome banner at startup
147160

148161
ls: {
149162
use_ls_colors: true # use the LS_COLORS environment variable to colorize output
@@ -210,7 +223,7 @@ $env.config = {
210223
external: {
211224
enable: true # set to false to prevent nushell looking into $env.PATH to find more suggestions, `false` recommended for WSL users as this look up may be very slow
212225
max_results: 100 # setting it lower can improve completion performance at the cost of omitting some options
213-
completer: null # check 'carapace_completer' above as an example
226+
completer: $external_completer # check 'carapace_completer' above as an example
214227
}
215228
}
216229

@@ -222,7 +235,7 @@ $env.config = {
222235
cursor_shape: {
223236
emacs: line # block, underscore, line, blink_block, blink_underscore, blink_line, inherit to skip setting cursor shape (line is the default)
224237
vi_insert: block # block, underscore, line, blink_block, blink_underscore, blink_line, inherit to skip setting cursor shape (block is the default)
225-
vi_normal: underscore # block, underscore, line, blink_block, blink_underscore, blink_line, inherit to skip setting cursor shape (underscore is the default)
238+
vi_normal: line # block, underscore, line, blink_block, blink_underscore, blink_line, inherit to skip setting cursor shape (underscore is the default)
226239
}
227240

228241
color_config: $dark_theme # if you want a more interesting theme, you can replace the empty record with `$dark_theme`, `$light_theme` or another custom record
@@ -235,7 +248,8 @@ $env.config = {
235248
edit_mode: vi # emacs, vi
236249
shell_integration: true # enables terminal shell integration. Off by default, as some terminals have issues with this.
237250
render_right_prompt_on_last_line: false # true or false to enable or disable right prompt to be rendered on last line of the prompt.
238-
use_kitty_protocol: true # enables keyboard enhancement protocol implemented by kitty console, only if your terminal support this.
251+
# enables keyboard enhancement protocol implemented by kitty console, only if your terminal support this.
252+
use_kitty_protocol: ($env.TERM == 'xterm-kitty')
239253
highlight_resolved_externals: true # true enables highlighting of external commands in the repl resolved by which.
240254

241255
plugins: {} # Per-plugin configuration. See https://www.nushell.sh/contributor-book/plugins.html#configuration.
@@ -839,37 +853,36 @@ $env.config = {
839853
]
840854
}
841855

842-
source ~/.cache/zoxide.nu
843-
use ~/.cache/starship.nu
844-
845-
alias vim = nvim
846-
alias vimdiff = nvim -d
847856
alias please = sudo (history | last | get command)
848-
alias say = espeak -p 10 -s 150 -a 200
849-
alias tmux = tmux -u
850-
alias pdfmk = latexmk -lualatex -pvc
851857
alias la = ls -a
852858
alias ll = ls -l
853859
alias lla = ls -la
854-
# needs to have a number immediately after it.
855-
alias slideshow = feh --full-screen --randomize --auto-zoom --recursive --slideshow-delay
860+
alias pyactivate = overlay use ./.venv/bin/activate
861+
alias say = espeak -p 10 -s 150 -a 200
862+
alias tmux = tmux -u
863+
alias pdfmk = latexmk -lualatex -pvc
856864
# converts all .doc and .docx files in the local directory to pdfs using libreoffice
857865
alias doc2pdf = loffice --convert-to pdf --headless *.docx
858866
#common options for sshfs
859867
alias sshmnt = sshfs -o idmap=user,compression=no,reconnect,follow_symlinks,dir_cache=yes,ServerAliveInterval=15
860-
alias pyactivate = overlay use ./.venv/bin/activate
861868

862-
# parses git log into a nushell table.
863-
def git-log [] {
864-
git log --pretty=%h»¦«%H»¦«%s»¦«%aN»¦«%aE»¦«%aD | lines | split column "»¦«" commit full-commit subject name email date | upsert date {|d| $d.date | into datetime}
869+
# display a slideshow of all pics in a directory, recursively
870+
def slideshow [delay: int = 10] {
871+
feh --full-screen --randomize --auto-zoom --recursive --slideshow-delay $delay
865872
}
866873

867-
# parses git log into a nushell table, lists all commits
868-
def git-log-all [] {
869-
git log --all --pretty=%h»¦«%H»¦«%s»¦«%aN»¦«%aE»¦«%aD | lines | split column "»¦«" commit full-commit subject name email date | upsert date {|d| $d.date | into datetime}
874+
# parses git log into a nushell table.
875+
def --wrapped git-log [...rest] {
876+
git log --pretty=%h»¦«%H»¦«%s»¦«%aN»¦«%aE»¦«%aD ...$rest | lines | split column "»¦«" commit full-commit subject name email date | upsert date {|d| $d.date | into datetime}
870877
}
871878

872879
# lists all the authors and how many commits they made in a histogram
873880
def git-authors [] {
874-
git-log-all | select name date | histogram name | select name count frequency
881+
git-log --all | select name date | histogram name
875882
}
883+
884+
# source the conditional config file that contains
885+
# all the definitions, aliases, and env vars we want to set conditionally.
886+
const conditional_config = ($nu.temp-path | path join 'conditional-config.nu')
887+
source $conditional_config
888+
rm $conditional_config

nushell/.config/nushell/env.nu

+23-8
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,29 @@ def is-installed [ app: string ] {
106106
$env.PATH = ($env.PATH | split row (char esep) | append ($nu.home-path | path join ".local/bin/"))
107107
$env.PATH = ($env.PATH | split row (char esep) | append ($nu.home-path | path join ".cargo/bin/"))
108108
$env.PATH = ($env.PATH | split row (char esep) | append ($nu.home-path | path join "opt"))
109-
110-
zoxide init nushell | save -f ~/.cache/zoxide.nu
111-
starship init nu | save -f ~/.cache/starship.nu
112-
113-
# we use the ssh systemd service.
114-
$env.SSH_AUTH_SOCK = $"($env.XDG_RUNTIME_DIR)/ssh-agent.socket"
115-
$env.EDITOR = nvim
116-
$env.VISUAL = nvim
117109
$env.PAGER = less
118110
$env.LESS = '-R'
119111
$env.LESSHISTFILE = '/dev/null'
112+
if "XDG_RUNTIME_DIR" in $env {
113+
$env.SSH_AUTH_SOCK = $"($env.XDG_RUNTIME_DIR)/ssh-agent.socket"
114+
}
115+
116+
const conditional_config = ($nu.temp-path | path join 'conditional-config.nu')
117+
'# This file is an ugly hack to conditionally source files and define aliases/custom commands.
118+
' | save --force $conditional_config
119+
120+
if (is-installed zoxide) {
121+
zoxide init nushell | save --append $conditional_config
122+
}
123+
if (is-installed starship) {
124+
starship init nu | save --append $conditional_config
125+
}
126+
if (is-installed nvim) {
127+
$env.EDITOR = nvim
128+
$env.VISUAL = nvim
129+
'alias vim = nvim
130+
alias vimdiff = nvim -d
131+
' | save --append $conditional_config
132+
}
133+
ls ($nu.default-config-dir | path join 'scripts/**/*.nu') |
134+
each { |it| $"source ($it.name)\n" | save --append $conditional_config} | null

0 commit comments

Comments
 (0)