feat(nushell): re-export completions for use-based startup
- switch completion module imports to export use so externs propagate - extend managed completion command set and required file checks - rename prompt static cache env var to PJ_LEFT_PROMPT_STATIC_PART - load completion module via use in nu_polyjuice
This commit is contained in:
@@ -1,4 +1,21 @@
|
|||||||
def "pj completion" [
|
const pj_module_dir = (path self | path dirname)
|
||||||
|
const pj_completion_base_dir = ($pj_module_dir | path join '..' 'cache' 'nu_scripts' 'custom-completions')
|
||||||
|
const pj_completion_commands = [git ssh cargo uv rustup make pytest rg tar fzf vscode winget zig]
|
||||||
|
|
||||||
|
def _pj_completion_script_path [name: string] {
|
||||||
|
($pj_completion_base_dir | path join $name $"($name)-completions.nu")
|
||||||
|
}
|
||||||
|
|
||||||
|
def _pj_required_completion_files [] {
|
||||||
|
$pj_completion_commands | each {|name|
|
||||||
|
{
|
||||||
|
command: $name
|
||||||
|
file: (_pj_completion_script_path $name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export def "pj completion" [
|
||||||
--update(-u) # Pull latest changes when repo already exists.
|
--update(-u) # Pull latest changes when repo already exists.
|
||||||
--force(-f) # Re-clone even when repo already exists.
|
--force(-f) # Re-clone even when repo already exists.
|
||||||
] {
|
] {
|
||||||
@@ -47,18 +64,11 @@ def "pj completion" [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let required = [
|
let required = (_pj_required_completion_files)
|
||||||
($completion_dir | path join 'git' 'git-completions.nu')
|
let missing = ($required | where {|it| not ($it.file | path exists) })
|
||||||
($completion_dir | path join 'ssh' 'ssh-completions.nu')
|
|
||||||
($completion_dir | path join 'cargo' 'cargo-completions.nu')
|
|
||||||
($completion_dir | path join 'uv' 'uv-completions.nu')
|
|
||||||
($completion_dir | path join 'rustup' 'rustup-completions.nu')
|
|
||||||
]
|
|
||||||
|
|
||||||
let missing = ($required | where {|f| not ($f | path exists) })
|
|
||||||
if not ($missing | is-empty) {
|
if not ($missing | is-empty) {
|
||||||
print "[pj completion] warning: some required completion files are missing:"
|
print "[pj completion] warning: some required completion files are missing:"
|
||||||
$missing | each {|f| print $" - ($f)" }
|
$missing | each {|it| print $" - ($it.command): ($it.file)" }
|
||||||
}
|
}
|
||||||
|
|
||||||
print "[pj completion] ok"
|
print "[pj completion] ok"
|
||||||
@@ -66,6 +76,7 @@ def "pj completion" [
|
|||||||
cache_dir: $cache_dir
|
cache_dir: $cache_dir
|
||||||
repo_dir: $repo_dir
|
repo_dir: $repo_dir
|
||||||
completion_dir: $completion_dir
|
completion_dir: $completion_dir
|
||||||
|
commands: $pj_completion_commands
|
||||||
missing_files: $missing
|
missing_files: $missing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,36 +96,16 @@ export-env {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const pj_module_dir = (path self | path dirname)
|
# Re-export imported extern signatures so they are visible when this module is `use`d.
|
||||||
|
export use ($pj_completion_base_dir | path join 'git' 'git-completions.nu') *
|
||||||
const git_completion = if (($pj_module_dir | path join '..' 'cache' 'nu_scripts' 'custom-completions' 'git' 'git-completions.nu') | path exists) {
|
export use ($pj_completion_base_dir | path join 'ssh' 'ssh-completions.nu') *
|
||||||
($pj_module_dir | path join '..' 'cache' 'nu_scripts' 'custom-completions' 'git' 'git-completions.nu')
|
export use ($pj_completion_base_dir | path join 'cargo' 'cargo-completions.nu') *
|
||||||
} else {
|
export use ($pj_completion_base_dir | path join 'uv' 'uv-completions.nu') *
|
||||||
null
|
export use ($pj_completion_base_dir | path join 'rustup' 'rustup-completions.nu') *
|
||||||
}
|
export use ($pj_completion_base_dir | path join 'make' 'make-completions.nu') *
|
||||||
const ssh_completion = if (($pj_module_dir | path join '..' 'cache' 'nu_scripts' 'custom-completions' 'ssh' 'ssh-completions.nu') | path exists) {
|
export use ($pj_completion_base_dir | path join 'pytest' 'pytest-completions.nu') *
|
||||||
($pj_module_dir | path join '..' 'cache' 'nu_scripts' 'custom-completions' 'ssh' 'ssh-completions.nu')
|
export use ($pj_completion_base_dir | path join 'rg' 'rg-completions.nu') *
|
||||||
} else {
|
export use ($pj_completion_base_dir | path join 'tar' 'tar-completions.nu') *
|
||||||
null
|
export use ($pj_completion_base_dir | path join 'vscode' 'vscode-completions.nu') *
|
||||||
}
|
export use ($pj_completion_base_dir | path join 'winget' 'winget-completions.nu') *
|
||||||
const cargo_completion = if (($pj_module_dir | path join '..' 'cache' 'nu_scripts' 'custom-completions' 'cargo' 'cargo-completions.nu') | path exists) {
|
export use ($pj_completion_base_dir | path join 'zig' 'zig-completions.nu') *
|
||||||
($pj_module_dir | path join '..' 'cache' 'nu_scripts' 'custom-completions' 'cargo' 'cargo-completions.nu')
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
const uv_completion = if (($pj_module_dir | path join '..' 'cache' 'nu_scripts' 'custom-completions' 'uv' 'uv-completions.nu') | path exists) {
|
|
||||||
($pj_module_dir | path join '..' 'cache' 'nu_scripts' 'custom-completions' 'uv' 'uv-completions.nu')
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
const rustup_completion = if (($pj_module_dir | path join '..' 'cache' 'nu_scripts' 'custom-completions' 'rustup' 'rustup-completions.nu') | path exists) {
|
|
||||||
($pj_module_dir | path join '..' 'cache' 'nu_scripts' 'custom-completions' 'rustup' 'rustup-completions.nu')
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
use $git_completion *
|
|
||||||
use $ssh_completion *
|
|
||||||
use $cargo_completion *
|
|
||||||
use $uv_completion *
|
|
||||||
use $rustup_completion *
|
|
||||||
|
|||||||
@@ -572,7 +572,7 @@ def _pj_prompt_static_base [] {
|
|||||||
|
|
||||||
def _pj_left_prompt [] {
|
def _pj_left_prompt [] {
|
||||||
let p = ($env.PJ_PROMPT_PALETTE? | default (_pj_palette_default))
|
let p = ($env.PJ_PROMPT_PALETTE? | default (_pj_palette_default))
|
||||||
let static = ($env.PJ_PROMPT_STATIC? | default (_pj_prompt_static_base))
|
let static = ($env.PJ_LEFT_PROMPT_STATIC_PART? | default (_pj_prompt_static_base))
|
||||||
|
|
||||||
let user_color = if ($static.effective_user == "root") { $p.c_root } else { $p.c_user }
|
let user_color = if ($static.effective_user == "root") { $p.c_root } else { $p.c_user }
|
||||||
|
|
||||||
@@ -635,7 +635,7 @@ export-env {
|
|||||||
load-env {
|
load-env {
|
||||||
PJ_PROMPT_PALETTE: (_pj_palette_default)
|
PJ_PROMPT_PALETTE: (_pj_palette_default)
|
||||||
PJ_OS_KEY: (_pj_detect_os_key)
|
PJ_OS_KEY: (_pj_detect_os_key)
|
||||||
PJ_PROMPT_STATIC: (_pj_prompt_static_base)
|
PJ_LEFT_PROMPT_STATIC_PART: (_pj_prompt_static_base)
|
||||||
PROMPT_MULTILINE_INDICATOR: ":"
|
PROMPT_MULTILINE_INDICATOR: ":"
|
||||||
PROMPT_INDICATOR: {||
|
PROMPT_INDICATOR: {||
|
||||||
_pj_prompt_indicator
|
_pj_prompt_indicator
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ $env.NU_POLYJUICE_PATH = $env.FILE_PWD
|
|||||||
|
|
||||||
# modules
|
# modules
|
||||||
use modules/pj_aliases.nu *
|
use modules/pj_aliases.nu *
|
||||||
source modules/pj_completions.nu
|
use modules/pj_completions.nu *
|
||||||
use modules/pj_helix.nu *
|
use modules/pj_helix.nu *
|
||||||
use modules/pj_fzf.nu *
|
use modules/pj_fzf.nu *
|
||||||
use modules/pj_zoxide.nu *
|
use modules/pj_zoxide.nu *
|
||||||
|
|||||||
Reference in New Issue
Block a user