1
0

Update nushell configuration for the new version

This commit is contained in:
Jip J. Dekker 2022-03-31 14:39:27 +11:00
parent d69302292e
commit fe637a8c66
No known key found for this signature in database
GPG Key ID: 517DF4A00618C9C3
3 changed files with 170 additions and 67 deletions

View File

@ -0,0 +1,158 @@
# Nushell Config File
let $config = ($config | upsert rm_always_trash true)
let $config = ($config | upsert edit_mode vi)
let $config = ($config | upsert max_history_size 100000)
let $config = ($config | upsert footer_mode auto)
# Specifies how environment variables are:
# - converted from a string to a value on Nushell startup (from_string)
# - converted from a value back to a string when running external commands (to_string)
# Note: The conversions happen *after* config.nu is loaded
let-env ENV_CONVERSIONS = {
"PATH": {
from_string: { |s| $s | split row (char esep) }
to_string: { |v| $v | str collect (char esep) }
}
"Path": {
from_string: { |s| $s | split row (char esep) }
to_string: { |v| $v | str collect (char esep) }
}
}
# Directories to search for scripts when calling source or use
#
# By default, <nushell-config-dir>/scripts is added
let-env NU_LIB_DIRS = [
($nu.config-path | path dirname | path join 'scripts')
]
# Directories to search for plugin binaries when calling register
#
# By default, <nushell-config-dir>/plugins is added
let-env NU_PLUGIN_DIRS = [
($nu.config-path | path dirname | path join 'plugins')
]
module completions {
# Custom completions for external commands (those outside of Nushell)
# Each completions has two parts: the form of the external command, including its flags and parameters
# and a helper command that knows how to complete values for those flags and parameters
#
# This is a simplified version of completions for git branches and git remotes
def "nu-complete git branches" [] {
^git branch | lines | each { |line| $line | str find-replace '\* ' '' | str trim }
}
def "nu-complete git remotes" [] {
^git remote | lines | each { |line| $line | str trim }
}
export extern "git checkout" [
branch?: string@"nu-complete git branches" # name of the branch to checkout
-b: string # create and checkout a new branch
-B: string # create/reset and checkout a branch
-l # create reflog for new branch
--guess # second guess 'git checkout <no-such-branch>' (default)
--overlay # use overlay mode (default)
--quiet(-q) # suppress progress reporting
--recurse-submodules: string # control recursive updating of submodules
--progress # force progress reporting
--merge(-m) # perform a 3-way merge with the new branch
--conflict: string # conflict style (merge or diff3)
--detach(-d) # detach HEAD at named commit
--track(-t) # set upstream info for new branch
--force(-f) # force checkout (throw away local modifications)
--orphan: string # new unparented branch
--overwrite-ignore # update ignored files (default)
--ignore-other-worktrees # do not check if another worktree is holding the given ref
--ours(-2) # checkout our version for unmerged files
--theirs(-3) # checkout their version for unmerged files
--patch(-p) # select hunks interactively
--ignore-skip-worktree-bits # do not limit pathspecs to sparse entries only
--pathspec-from-file: string # read pathspec from file
]
export extern "git push" [
remote?: string@"nu-complete git remotes", # the name of the remote
refspec?: string@"nu-complete git branches"# the branch / refspec
--verbose(-v) # be more verbose
--quiet(-q) # be more quiet
--repo: string # repository
--all # push all refs
--mirror # mirror all refs
--delete(-d) # delete refs
--tags # push tags (can't be used with --all or --mirror)
--dry-run(-n) # dry run
--porcelain # machine-readable output
--force(-f) # force updates
--force-with-lease: string # require old value of ref to be at this value
--recurse-submodules: string # control recursive pushing of submodules
--thin # use thin pack
--receive-pack: string # receive pack program
--exec: string # receive pack program
--set-upstream(-u) # set upstream for git pull/status
--progress # force progress reporting
--prune # prune locally removed refs
--no-verify # bypass pre-push hook
--follow-tags # push missing but relevant tags
--signed: string # GPG sign the push
--atomic # request atomic transaction on remote side
--push-option(-o): string # option to transmit
--ipv4(-4) # use IPv4 addresses only
--ipv6(-6) # use IPv6 addresses only
]
}
# Get just the extern definitions without the custom completion commands
use completions *
### Manage PATH
# Optional Homebrew packages
let-env PATH = ($env.PATH | prepend $'(brew --prefix | str trim)/opt/bison/bin')
let-env PATH = ($env.PATH | prepend $'(brew --prefix | str trim)/opt/flex/bin')
let-env PATH = ($env.PATH | prepend $'(brew --prefix | str trim)/opt/llvm/bin')
let-env PATH = ($env.PATH | prepend $'(brew --prefix | str trim)/opt/openjdk/bin')
# Other package managers
let-env PATH = ($env.PATH | prepend "~/.local/bin")
let-env PATH = ($env.PATH | prepend "~/.cargo/bin")
# From MacOS helper (/usr/libexec/path_helper)
let-env PATH = ($env.PATH | append "/Library/TeX/texbin")
let-env PATH = ($env.PATH | append "/Library/Apple/usr/bin")
### Setup aliases
alias edit = ^($env.EDITOR)
alias set-light-theme = kitty +kitten themes Rosé Pine Dawn
alias set-dark-theme = kitty +kitten themes Rosé Pine Moon
alias brew-backup = brew bundle dump --global --no-lock --cask --mas --tap --force
alias brew-cleanup = brew bundle cleanup --global --no-lock --force --zap
alias brew-restore = brew bundle install --global --no-lock
alias packer-sync = nvim --headless -c "autocmd User PackerComplete quitall" -c "PackerSync"
### Environment
# Set default editor
let-env EDITOR = "nvim"
# Alias for Monash compute cluster
let-env BIGBAD = "compute.optimisation-2020.cloud.edu.au"
# CMake settings
let-env CMAKE_EXPORT_COMPILE_COMMANDS = "1" # output compile-commands.json for clangd
let-env CMAKE_GENERATOR = "Ninja Multi-Config" # use Ninja generator by default
# Default find command for FZF
let-env FZF_DEFAULT_COMMAND = "fd --type f"
# Homebrew shell setup (brew shellenv)
let-env HOMEBREW_PREFIX = "/opt/homebrew"
let-env HOMEBREW_CELLAR = "/opt/homebrew/Cellar"
let-env HOMEBREW_REPOSITORY = "/opt/homebrew"
let-env HOMEBREW_SHELLENV_PREFIX = "/opt/homebrew"
let-env INFOPATH = "/opt/homebrew/share/info"
# Set MANPATH
let-env MANPATH = "/usr/share/man:/usr/local/share/man:/Library/TeX/Distributions/.DefaultTeX/Contents/Man:/opt/homebrew/share/man"
# Load autojump plugin "zoxide"
# source ~/.cache/zoxide/zoxide.nu
# Load standardised prompt "starship"
# TEMP: Custom vi prompt indicators
let-env PROMPT_INDICATOR_VI_INSERT = "✏️ "
let-env PROMPT_INDICATOR_VI_NORMAL = "🔙 "
source ~/.cache/starship/init.nu

View File

@ -1,67 +0,0 @@
completion_type = "list"
prompt = "starship prompt"
rm_always_trash = true
table_mode = "rounded"
path = [
"/usr/local/bin",
"/usr/bin",
"/bin",
"/usr/sbin",
"/sbin",
# From MacOS helper (/usr/libexec/path_helper)
"/Library/TeX/texbin",
"/Library/Apple/usr/bin",
# Terminal emulator
"/Applications/kitty.app/Contents/MacOS",
# Homebrew binary directories
"/opt/homebrew/bin",
"/opt/homebrew/sbin",
]
startup = [
"alias edit = ^($nu.env.EDITOR)",
"alias set-light-theme = kitty +kitten themes Rosé Pine Dawn",
"alias set-dark-theme = kitty +kitten themes Rosé Pine Moon",
"alias brew-backup = brew bundle dump --global --no-lock --cask --mas --tap --force",
"alias brew-cleanup = brew bundle cleanup --global --no-lock --force --zap",
"alias brew-restore = brew bundle install --global --no-lock",
"alias packer-sync = nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'",
# Optional binaries from Homebrew
"pathvar add $'(brew --prefix | str trim)/opt/bison/bin'",
"pathvar add $'(brew --prefix | str trim)/opt/flex/bin'",
"pathvar add $'(brew --prefix | str trim)/opt/llvm/bin'",
"pathvar add $'(brew --prefix | str trim)/opt/openjdk/bin'",
"pathvar append ~/.local/bin", # pipx binaries
"pathvar append ~/.cargo/bin", # cargo binaries
# Zoxide autojump
"zoxide init nushell --hook prompt | save ~/.config/nu/zoxide.nu", "source ~/.config/nu/zoxide.nu",
]
[line_editor]
completion_match_method = "case-insensitive"
edit_mode = "vi"
max_history_size = 100000
tab_stop = 2
[env]
# Set default editor
EDITOR = "nvim"
# Alias for Monash compute cluster
BIGBAD = "compute.optimisation-2020.cloud.edu.au"
# CMake settings
CMAKE_EXPORT_COMPILE_COMMANDS = "1" # output compile-commands.json for clangd
CMAKE_GENERATOR = "Ninja Multi-Config" # use Ninja generator by default
# Default find command for FZF
FZF_DEFAULT_COMMAND = "fd --type f"
# Homebrew shell setup (brew shellenv)
HOMEBREW_PREFIX = "/opt/homebrew"
HOMEBREW_CELLAR = "/opt/homebrew/Cellar"
HOMEBREW_REPOSITORY = "/opt/homebrew"
HOMEBREW_SHELLENV_PREFIX = "/opt/homebrew"
INFOPATH = "/opt/homebrew/share/info"
# Set MANPATH
MANPATH = "/usr/share/man:/usr/local/share/man:/Library/TeX/Distributions/.DefaultTeX/Contents/Man:/opt/homebrew/share/man"

12
run_nushell_generation.nu Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env nu
# Generate zoxide configuration
if (which zoxide | empty?) == false {
mkdir ~/.cache/zoxide/
zoxide init nushell --hook prompt | save ~/.cache/zoxide/zoxide.nu
}
if (which starship | empty?) == false {
mkdir ~/.cache/starship/
starship init nu | save ~/.cache/starship/init.nu
}