feat(nushell): add cached nu_scripts completions bootstrap
- add pj completion command to clone/update nu_scripts cache - load fixed custom-completions for git/ssh/cargo/uv/rustup from cache - ignore nushell/cache contents in git while keeping placeholder .gitignore - source pj_completions at startup and align prompt indicators/newline behavior
This commit is contained in:
@@ -1,2 +1,4 @@
|
|||||||
.zed
|
.zed
|
||||||
.vscode
|
.vscode
|
||||||
|
nushell/cache/*
|
||||||
|
!nushell/cache/.gitignore
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
@@ -1,3 +1,75 @@
|
|||||||
|
def "pj completion" [
|
||||||
|
--update(-u) # Pull latest changes when repo already exists.
|
||||||
|
--force(-f) # Re-clone even when repo already exists.
|
||||||
|
] {
|
||||||
|
let repo_url = "https://github.com/nushell/nu_scripts.git"
|
||||||
|
let cache_dir = if ('NU_POLYJUICE_PATH' in $env) {
|
||||||
|
($env.NU_POLYJUICE_PATH | path join 'cache')
|
||||||
|
} else {
|
||||||
|
(pwd | path join 'nushell' 'cache')
|
||||||
|
}
|
||||||
|
let repo_dir = ($cache_dir | path join 'nu_scripts')
|
||||||
|
let completion_dir = ($repo_dir | path join 'custom-completions')
|
||||||
|
|
||||||
|
if (which git | is-empty) {
|
||||||
|
error make {
|
||||||
|
msg: "`git` command is required for pj completion"
|
||||||
|
help: "Install Git first, then run `pj completion` again."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mkdir $cache_dir
|
||||||
|
|
||||||
|
if $force {
|
||||||
|
if ($repo_dir | path exists) {
|
||||||
|
rm -rf $repo_dir
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if not ($repo_dir | path exists) {
|
||||||
|
print "[pj completion] nu_scripts cache not found, cloning..."
|
||||||
|
^git clone $repo_url $repo_dir
|
||||||
|
} else {
|
||||||
|
if not (($repo_dir | path join '.git') | path exists) {
|
||||||
|
print "[pj completion] existing cache is not a git repo, re-cloning..."
|
||||||
|
rm -rf $repo_dir
|
||||||
|
^git clone $repo_url $repo_dir
|
||||||
|
} else if $update {
|
||||||
|
print "[pj completion] cache exists, updating..."
|
||||||
|
^git -C $repo_dir pull --ff-only
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if not ($completion_dir | path exists) {
|
||||||
|
error make {
|
||||||
|
msg: "nu_scripts cloned, but custom-completions directory is missing"
|
||||||
|
help: $"Check repository content under ($repo_dir)."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let required = [
|
||||||
|
($completion_dir | path join 'git' 'git-completions.nu')
|
||||||
|
($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) {
|
||||||
|
print "[pj completion] warning: some required completion files are missing:"
|
||||||
|
$missing | each {|f| print $" - ($f)" }
|
||||||
|
}
|
||||||
|
|
||||||
|
print "[pj completion] ok"
|
||||||
|
{
|
||||||
|
cache_dir: $cache_dir
|
||||||
|
repo_dir: $repo_dir
|
||||||
|
completion_dir: $completion_dir
|
||||||
|
missing_files: $missing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export-env {
|
export-env {
|
||||||
$env.config = {
|
$env.config = {
|
||||||
completions: {
|
completions: {
|
||||||
@@ -12,3 +84,37 @@ export-env {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pj_module_dir = (path self | path dirname)
|
||||||
|
|
||||||
|
const git_completion = if (($pj_module_dir | path join '..' 'cache' 'nu_scripts' 'custom-completions' 'git' 'git-completions.nu') | path exists) {
|
||||||
|
($pj_module_dir | path join '..' 'cache' 'nu_scripts' 'custom-completions' 'git' 'git-completions.nu')
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
const ssh_completion = if (($pj_module_dir | path join '..' 'cache' 'nu_scripts' 'custom-completions' 'ssh' 'ssh-completions.nu') | path exists) {
|
||||||
|
($pj_module_dir | path join '..' 'cache' 'nu_scripts' 'custom-completions' 'ssh' 'ssh-completions.nu')
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
const cargo_completion = if (($pj_module_dir | path join '..' 'cache' 'nu_scripts' 'custom-completions' 'cargo' 'cargo-completions.nu') | path exists) {
|
||||||
|
($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 *
|
||||||
|
|||||||
@@ -605,7 +605,8 @@ def _pj_left_prompt [] {
|
|||||||
for m in $lang_parts {
|
for m in $lang_parts {
|
||||||
$out = $"($out)($m)"
|
$out = $"($out)($m)"
|
||||||
}
|
}
|
||||||
$out = $"\n($out)($time_part)($duration_part)\n"
|
let prompt_newline = if (($nu.os-info.name | str downcase) == "windows") { "\n\r" } else { "\n" }
|
||||||
|
$out = $"($prompt_newline)($out)($time_part)($duration_part)($prompt_newline)"
|
||||||
$out
|
$out
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -626,8 +627,12 @@ export-env {
|
|||||||
PROMPT_INDICATOR: {||
|
PROMPT_INDICATOR: {||
|
||||||
_pj_prompt_indicator
|
_pj_prompt_indicator
|
||||||
}
|
}
|
||||||
PROMPT_INDICATOR_VI_INSERT: ""
|
PROMPT_INDICATOR_VI_INSERT: {||
|
||||||
PROMPT_INDICATOR_VI_NORMAL: ""
|
_pj_prompt_indicator
|
||||||
|
}
|
||||||
|
PROMPT_INDICATOR_VI_NORMAL: {||
|
||||||
|
_pj_prompt_indicator
|
||||||
|
}
|
||||||
PROMPT_COMMAND: {||
|
PROMPT_COMMAND: {||
|
||||||
_pj_left_prompt
|
_pj_left_prompt
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ $env.NU_POLYJUICE_PATH = $env.FILE_PWD
|
|||||||
|
|
||||||
# modules
|
# modules
|
||||||
use modules/pj_aliases.nu *
|
use modules/pj_aliases.nu *
|
||||||
use modules/pj_completions.nu *
|
source 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