mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 22:57:46 +00:00
refactor: introduce spr
and sprb
for spread (#504)
* refactor: introduce `spr` and `sprb` for spread - eliminate `if ($n|is-empty) { [] } else { [-n $n] }` pattern - `gp -u` can omit branch - delete `grb` - improve the premise in the description * commands for helm as `kxh` - add `(kustomize)` to description of kxk - add commands for helm - kgh - kdh - kah - kdelh - kh - add `nu-complete kube port` of `kpf` - add `--local` flag for `kpf` --------- Co-authored-by: agent <agent@nuc>
This commit is contained in:
parent
fe594febea
commit
ebc16108fb
4 changed files with 264 additions and 138 deletions
|
@ -34,17 +34,18 @@ If there is no branch as an argument, the branch is displayed.
|
|||
### gp
|
||||
Pull, push and other related to remote repositories
|
||||
|
||||
> We assume that the upstream and downstream branches keep the same name and do not operate across branches.
|
||||
|
||||
- `--clone` to clone
|
||||
- `--submodule` submodule update and submodule init (with `--init`)
|
||||
- `--force` push --force (assume `pull --force` doesn't make sense)
|
||||
- `--init` git init
|
||||
- `--override` just used to trigger a github actions event (in fact, webhooks can also be used)
|
||||
- if branch is specified, we assume it is `git fetch`
|
||||
- unless -u is specified: `git push -u`
|
||||
- `--set-upstream` push --set-upstream
|
||||
- if branch is specified, it is `git fetch` (let's assume you don't like pulling from a different branch)
|
||||
- finally, if no branch and above parameters are specified
|
||||
- `git fetch` to update status.
|
||||
- `git pull` or `git push` will be executed according to the current state.
|
||||
- if both `ahead` and `behind` exist, only `pull`
|
||||
- `git pull` to update.
|
||||
- if `ahead`, `git push` will be executed.
|
||||
|
||||
### ga
|
||||
Git add, rm and restore. about files.
|
||||
|
@ -79,3 +80,10 @@ Git remote
|
|||
|
||||
### gbs
|
||||
Git bisect
|
||||
|
||||
## changelog
|
||||
|
||||
#### 2023-05-18
|
||||
- `gp -u` can omit branch
|
||||
- delete `grb`
|
||||
- improve the premise in the description
|
||||
|
|
|
@ -7,6 +7,28 @@ def agree [prompt] {
|
|||
([yes no] | input list $prompt) in [yes]
|
||||
}
|
||||
|
||||
def sprb [flag, args] {
|
||||
if $flag {
|
||||
$args
|
||||
} else {
|
||||
[]
|
||||
}
|
||||
}
|
||||
|
||||
def spr [args] {
|
||||
let lst = ($args | last)
|
||||
if ($lst | is-empty) {
|
||||
[]
|
||||
} else {
|
||||
let init = ($args | range ..-2)
|
||||
if ($init | is-empty) {
|
||||
[ $lst ]
|
||||
} else {
|
||||
$init | append $lst
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# git status and stash
|
||||
export def gs [
|
||||
--apply (-a): bool
|
||||
|
@ -31,8 +53,7 @@ export def gs [
|
|||
} else if $show {
|
||||
git stash show --text
|
||||
} else if $all {
|
||||
let iu = if $include_untracked { [--include-untracked] } else { [] }
|
||||
git stash --all $iu
|
||||
git stash --all (sprb $include_untracked [--include-untracked])
|
||||
} else {
|
||||
git status
|
||||
}
|
||||
|
@ -96,8 +117,7 @@ export def gp [
|
|||
--autostash (-a): bool # git pull --autostash
|
||||
] {
|
||||
if not ($clone | is-empty) {
|
||||
let s = if $submodule { [--recurse-submodules] } else { [] }
|
||||
git clone $s $clone
|
||||
git clone (sprb $submodule [--recurse-submodules]) $clone
|
||||
} else if $submodule {
|
||||
if $init {
|
||||
git submodule init
|
||||
|
@ -114,16 +134,16 @@ export def gp [
|
|||
git add --all
|
||||
git commit -v -a --no-edit --amend
|
||||
git push --force
|
||||
} else if $set_upstream {
|
||||
let remote = if ($remote | is-empty) { 'origin' } else { $remote }
|
||||
let branch = if ($branch | is-empty) { (_git_status).branch } else { $branch }
|
||||
git push -u $remote $branch
|
||||
} else if not ($branch | is-empty) {
|
||||
let remote = if ($remote|is-empty) { 'origin' } else { $remote }
|
||||
if $set_upstream {
|
||||
git push -u $remote $branch
|
||||
} else {
|
||||
git fetch $remote $branch
|
||||
}
|
||||
git fetch $remote $branch
|
||||
} else {
|
||||
let r = if $rebase { [--rebase] } else { [] }
|
||||
let a = if $autostash { [--autostash] } else { [] }
|
||||
let r = (sprb $rebase [--rebase])
|
||||
let a = (sprb $autostash [--autostash])
|
||||
git pull $r $a -v
|
||||
let s = (_git_status)
|
||||
if $s.ahead > 0 {
|
||||
|
@ -147,18 +167,18 @@ export def ga [
|
|||
--source (-o): string
|
||||
] {
|
||||
if $delete {
|
||||
let c = if $cached { [--cached] } else { [] }
|
||||
let f = if $force { [--force] } else { [] }
|
||||
git rm $c $file
|
||||
let c = (sprb $cached [--cached])
|
||||
let f = (sprb $force [--force])
|
||||
git rm $c $f $file
|
||||
} else if $restore {
|
||||
let o = if ($source | is-empty) { [] } else { [--source $source] }
|
||||
let s = if $staged { [--staged] } else { [] }
|
||||
let o = (spr [--source $source])
|
||||
let s = (sprb $staged [--staged])
|
||||
git restore $o $s $file
|
||||
} else {
|
||||
let a = if $all { [--all] } else { [] }
|
||||
let p = if $patch { [--patch] } else { [] }
|
||||
let u = if $update { [--update] } else { [] }
|
||||
let v = if $verbose { [--verbose] } else { [] }
|
||||
let a = (sprb $all [--all])
|
||||
let p = (sprb $patch [--patch])
|
||||
let u = (sprb $update [--update])
|
||||
let v = (sprb $verbose [--verbose])
|
||||
let file = if ($file | is-empty) { [.] } else { [$file] }
|
||||
git add $a $p $u $v $file
|
||||
}
|
||||
|
@ -172,10 +192,10 @@ export def gc [
|
|||
--amend (-a): bool
|
||||
--keep (-k): bool
|
||||
] {
|
||||
let m = if ($message | is-empty) { [] } else { [-m $message] }
|
||||
let a = if $all { [--all] } else { [] }
|
||||
let n = if $amend { [--amend] } else { [] }
|
||||
let k = if $keep { [--no-edit] } else { [] }
|
||||
let m = (spr [-m $message])
|
||||
let a = (sprb $all [--all])
|
||||
let n = (sprb $amend [--amend])
|
||||
let k = (sprb $keep [--no-edit])
|
||||
git commit -v $m $a $n $k
|
||||
}
|
||||
|
||||
|
@ -185,9 +205,9 @@ export def gd [
|
|||
--word-diff (-w): bool # word-diff
|
||||
--staged (-s): bool # staged
|
||||
] {
|
||||
let w = if $word_diff { [--word-diff] } else { [] }
|
||||
let c = if $cached { [--cached] } else { [] }
|
||||
let s = if $staged { [--staged] } else { [] }
|
||||
let w = (sprb $word_diff [--word-diff])
|
||||
let c = (sprb $cached [--cached])
|
||||
let s = (sprb $staged [--staged])
|
||||
git diff $c $s $w
|
||||
}
|
||||
|
||||
|
@ -254,8 +274,8 @@ export def gr [
|
|||
commit?: string@"nu-complete git log"
|
||||
--hard (-h): bool
|
||||
] {
|
||||
let h = if $hard { [--hard] } else { [] }
|
||||
let c = if ($commit | is-empty) { [] } else { [$commit] }
|
||||
let h = (sprb $hard [--hard])
|
||||
let c = (spr [$commit])
|
||||
git reset $h $c
|
||||
}
|
||||
|
||||
|
@ -323,11 +343,6 @@ export def gsq [] {
|
|||
git gc --prune=now --aggressive
|
||||
}
|
||||
|
||||
export def grb [branch:string@"nu-complete git branches"] {
|
||||
git rebase (gstat).branch $branch
|
||||
}
|
||||
|
||||
|
||||
export alias gcf = git config --list
|
||||
export alias gsw = git switch
|
||||
export alias gswc = git switch -c
|
||||
|
@ -504,6 +519,3 @@ def git_main_branch [] {
|
|||
| str replace 'HEAD .*?[:: ](.+)' '$1'
|
||||
}
|
||||
|
||||
def git_current_branch [] {
|
||||
(gstat).branch
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue