nushell: changes
This commit is contained in:
parent
ac489db754
commit
0fe5d8e650
3 changed files with 184 additions and 21 deletions
|
@ -2,9 +2,76 @@ let starship_installed = not (which starship | is-empty)
|
|||
let direnv_installed = not (which direnv | is-empty)
|
||||
let carapace_installed = not (which carapace | is-empty)
|
||||
|
||||
alias c = clear
|
||||
alias cc = cd; clear
|
||||
alias h = hx
|
||||
alias e = emacsclient
|
||||
alias g = git
|
||||
alias lg = lazygit
|
||||
# alias cd = z
|
||||
# alias ci = zi
|
||||
|
||||
|
||||
let zoxide_completer = {|spans|
|
||||
$spans | skip 1 | zoxide query -l ...$in | lines | where {|x| $x != $env.PWD}
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
let carapace_completer = {|spans: list<string>|
|
||||
carapace $spans.0 nushell ...$spans
|
||||
| from json
|
||||
| if ($in | default [] | where value =~ '^-.*ERR$' | is-empty) { $in } else { null }
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
let fish_completer = {|spans|
|
||||
fish --command $'complete "--do-complete=($spans | str join " ")"'
|
||||
| $"value(char tab)description(char newline)" + $in
|
||||
| from tsv --flexible --no-infer
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
# This completer will use carapace by default
|
||||
let external_completer = {|spans|
|
||||
let expanded_alias = scope aliases
|
||||
| where name == $spans.0
|
||||
| get -i 0.expansion
|
||||
|
||||
let spans = if $expanded_alias != null {
|
||||
$spans
|
||||
| skip 1
|
||||
| prepend ($expanded_alias | split row ' ' | take 1)
|
||||
} else {
|
||||
$spans
|
||||
}
|
||||
|
||||
match $spans.0 {
|
||||
# carapace completions are incorrect for nu
|
||||
nu => $fish_completer
|
||||
# fish completes commits and branch names in a nicer way
|
||||
git => $fish_completer
|
||||
# carapace doesn't have completions for asdf
|
||||
# asdf => $fish_completer
|
||||
# use zoxide completions for zoxide commands
|
||||
__zoxide_z | __zoxide_zi => $zoxide_completer
|
||||
_ => $carapace_completer
|
||||
} | do $in $spans
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
if $starship_installed {
|
||||
$env.STARSHIP_SHELL = "nu"
|
||||
$env.STARSHIP_SESSION_KEY = (random chars -l 16)
|
||||
$env.STARSHIP_SESSION_KEY = (random chars -l 16)
|
||||
$env.PROMPT_MULTILINE_INDICATOR = (starship prompt --continuation)
|
||||
$env.PROMPT_INDICATOR = ""
|
||||
$env.PROMPT_COMMAND = {|| starship prompt $"--cmd-duration=($env.CMD_DURATION_MS)" $"--status=($env.LAST_EXIT_CODE)" }
|
||||
$env.PROMPT_COMMAND_RIGHT = ''
|
||||
} else {}
|
||||
|
||||
# =============================================================================
|
||||
$env.config = {
|
||||
show_banner: false
|
||||
|
||||
|
||||
hooks: {
|
||||
pre_prompt: [{ ||
|
||||
|
@ -22,30 +89,17 @@ $env.config = {
|
|||
mode: compact
|
||||
index_mode: auto
|
||||
}
|
||||
|
||||
completions: {
|
||||
quick: true
|
||||
partial: true
|
||||
case_sensitive: false
|
||||
algorithm: "fuzzy"
|
||||
external: (if $carapace_installed {
|
||||
{
|
||||
external: {
|
||||
enable: true
|
||||
completer: { |spans| carapace $spans.0 nushell $spans | from json }
|
||||
completer: $external_completer
|
||||
max_results: 100
|
||||
}
|
||||
} else {
|
||||
{}
|
||||
})
|
||||
}}
|
||||
|
||||
|
||||
if $starship_installed {
|
||||
$env.STARSHIP_SHELL = "nu"
|
||||
$env.STARSHIP_SESSION_KEY = (random chars -l 16)
|
||||
$env.STARSHIP_SESSION_KEY = (random chars -l 16)
|
||||
$env.PROMPT_MULTILINE_INDICATOR = (starship prompt --continuation)
|
||||
# $env.PROMPT_INDICATOR = "$ "
|
||||
$env.PROMPT_COMMAND = {|| starship prompt $"--cmd-duration=($env.CMD_DURATION_MS)" $"--status=($env.LAST_EXIT_CODE)" }
|
||||
$env.PROMPT_COMMAND_RIGHT = ''
|
||||
} else {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,49 @@
|
|||
# empty
|
||||
# Code generated by zoxide. DO NOT EDIT.
|
||||
|
||||
# =============================================================================
|
||||
#
|
||||
# Hook configuration for zoxide.
|
||||
#
|
||||
|
||||
# Initialize hook to add new entries to the database.
|
||||
if (not ($env | default false __zoxide_hooked | get __zoxide_hooked)) {
|
||||
$env.__zoxide_hooked = true
|
||||
$env.config = ($env | default {} config).config
|
||||
$env.config = ($env.config | default {} hooks)
|
||||
$env.config = ($env.config | update hooks ($env.config.hooks | default {} env_change))
|
||||
$env.config = ($env.config | update hooks.env_change ($env.config.hooks.env_change | default [] PWD))
|
||||
$env.config = ($env.config | update hooks.env_change.PWD ($env.config.hooks.env_change.PWD | append {|_, 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 arg0 = ($rest | append '~').0
|
||||
let arg0_is_dir = (try {$arg0 | path expand | path type}) == 'dir'
|
||||
let path = if (($rest | length) <= 1) and ($arg0 == '-' or $arg0_is_dir) {
|
||||
$arg0
|
||||
} else {
|
||||
(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.
|
||||
#
|
||||
|
||||
alias cd = __zoxide_z
|
||||
alias ci = __zoxide_zi
|
||||
# =============================================================================
|
||||
|
|
61
parts/pkgs/extraPackages/nushell/init_zoxide.nu
Normal file
61
parts/pkgs/extraPackages/nushell/init_zoxide.nu
Normal file
|
@ -0,0 +1,61 @@
|
|||
# Code generated by zoxide. DO NOT EDIT.
|
||||
|
||||
# =============================================================================
|
||||
#
|
||||
# Hook configuration for zoxide.
|
||||
#
|
||||
|
||||
# Initialize hook to add new entries to the database.
|
||||
if (not ($env | default false __zoxide_hooked | get __zoxide_hooked)) {
|
||||
$env.__zoxide_hooked = true
|
||||
$env.config = ($env | default {} config).config
|
||||
$env.config = ($env.config | default {} hooks)
|
||||
$env.config = ($env.config | update hooks ($env.config.hooks | default {} env_change))
|
||||
$env.config = ($env.config | update hooks.env_change ($env.config.hooks.env_change | default [] PWD))
|
||||
$env.config = ($env.config | update hooks.env_change.PWD ($env.config.hooks.env_change.PWD | append {|_, 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 arg0 = ($rest | append '~').0
|
||||
let arg0_is_dir = (try {$arg0 | path expand | path type}) == 'dir'
|
||||
let path = if (($rest | length) <= 1) and ($arg0 == '-' or $arg0_is_dir) {
|
||||
$arg0
|
||||
} else {
|
||||
(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.
|
||||
#
|
||||
|
||||
alias z = __zoxide_z
|
||||
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+.
|
Loading…
Add table
Add a link
Reference in a new issue