mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-09 05:44:23 +00:00
chore(git-all): improve python and shell versions
This commit is contained in:
@@ -44,6 +44,35 @@ diff -y -W 200 \
|
|||||||
# Math.
|
# Math.
|
||||||
math 2 '+' 6
|
math 2 '+' 6
|
||||||
time pulumi pre --parallel (math 2 '*' (nproc))
|
time pulumi pre --parallel (math 2 '*' (nproc))
|
||||||
|
|
||||||
|
# Array manipulation.
|
||||||
|
echo (seq 10)[-1..1] # -> 10 9 8 7 6 5 4 3 2 1
|
||||||
|
set array "$array appended_element"
|
||||||
|
|
||||||
|
# Define CLI options.
|
||||||
|
# Use all lines.
|
||||||
|
set -l opts
|
||||||
|
set opts $opts (fish_opt -s 'c' -l 'command' --required-val)
|
||||||
|
set opts $opts (fish_opt -s 'p' -l 'path' --multiple-vals)
|
||||||
|
argparse $opts -- $argv
|
||||||
|
or return
|
||||||
|
echo $_flag_command
|
||||||
|
echo $_flag_path
|
||||||
|
echo $argv
|
||||||
|
|
||||||
|
# Switch.
|
||||||
|
switch $animal
|
||||||
|
case cat
|
||||||
|
echo evil
|
||||||
|
case wolf dog human moose dolphin whale
|
||||||
|
echo mammal
|
||||||
|
case duck goose albatross
|
||||||
|
echo bird
|
||||||
|
case shark trout stingray
|
||||||
|
echo fish
|
||||||
|
case '*'
|
||||||
|
echo I have no idea what a $animal is
|
||||||
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
For functions defined in files in `~/.config/fish/functions/` to be automatically available, the files need to:
|
For functions defined in files in `~/.config/fish/functions/` to be automatically available, the files need to:
|
||||||
|
|||||||
@@ -23,8 +23,9 @@ parallel -qt -j 1 \
|
|||||||
|
|
||||||
# Get the exit status of all subjobs ('--joblog $outfile').
|
# Get the exit status of all subjobs ('--joblog $outfile').
|
||||||
# Use all the threads you can (--jobs 0), hammering the CPU.
|
# Use all the threads you can (--jobs 0), hammering the CPU.
|
||||||
|
# Highlight in red jobs that failed.
|
||||||
find . -type d -name .git -exec dirname "{}" + \
|
find . -type d -name .git -exec dirname "{}" + \
|
||||||
| parallel --jobs 0 --tagstring {/} --joblog - \
|
| parallel --jobs 0 --color-failed --tagstring {/} --joblog - \
|
||||||
'git -C {} pull --recurse-submodules'
|
'git -C {} pull --recurse-submodules'
|
||||||
|
|
||||||
# Inject Istio's sidecar to all Deployments in a Namespace.
|
# Inject Istio's sidecar to all Deployments in a Namespace.
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ def main(debug, directories, dry_run, git_subcommand, recursive, threads, verbos
|
|||||||
|
|
||||||
pre_flight(git_subcommand=git_subcommand_parts[0])
|
pre_flight(git_subcommand=git_subcommand_parts[0])
|
||||||
|
|
||||||
repositories = list(directories)
|
repositories = []
|
||||||
if recursive:
|
if recursive:
|
||||||
for directory in directories:
|
for directory in directories:
|
||||||
logging.info(f"starting from '{directory}'")
|
logging.info(f"starting from '{directory}'")
|
||||||
@@ -104,7 +104,10 @@ def main(debug, directories, dry_run, git_subcommand, recursive, threads, verbos
|
|||||||
logging.debug(f"{directory} has repositories {', '.join(repositories_in_dir)}")
|
logging.debug(f"{directory} has repositories {', '.join(repositories_in_dir)}")
|
||||||
|
|
||||||
repositories.extend(repositories_in_dir)
|
repositories.extend(repositories_in_dir)
|
||||||
repositories = set(repositories)
|
else:
|
||||||
|
# Just trust the user gave repositories in input
|
||||||
|
repositories.extend(directories)
|
||||||
|
repositories = set(repositories)
|
||||||
logging.debug(f"repositories: {', '.join(repositories)}")
|
logging.debug(f"repositories: {', '.join(repositories)}")
|
||||||
|
|
||||||
logging.debug(f"creating threads")
|
logging.debug(f"creating threads")
|
||||||
|
|||||||
19
snippets/git.fish
Normal file
19
snippets/git.fish
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/env fish
|
||||||
|
|
||||||
|
function git-all
|
||||||
|
if ! which -s parallel
|
||||||
|
echo "GNU parallel not found" >&2
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
argparse -s 'c/command=' 'p/path=+' 'r/recursive' -- $argv
|
||||||
|
or return
|
||||||
|
|
||||||
|
if test "$_flag_recursive" = '-r' || test "$_flag_recursive" = '--recursive'
|
||||||
|
set repositories (find $_flag_path -type 'd' -name '.git' -exec dirname {} +)
|
||||||
|
else
|
||||||
|
set repositories $_flag_path
|
||||||
|
end
|
||||||
|
|
||||||
|
parallel --color-failed --tagstring "{/}" "git -C {} $_flag_command" ::: $repositories
|
||||||
|
end
|
||||||
@@ -12,6 +12,7 @@ git config --local 'commit.gpgsign' true
|
|||||||
git config --local 'pull.rebase' false
|
git config --local 'pull.rebase' false
|
||||||
|
|
||||||
git clone --recurse-submodules 'git@github.com:example/ansible-role-keychron-capable.git'
|
git clone --recurse-submodules 'git@github.com:example/ansible-role-keychron-capable.git'
|
||||||
|
git clone 'https://gitlab-ci-token:glpat-01234567ABCDEFGHijkl@gitlab.example.org/testProj/myRepo.git'
|
||||||
|
|
||||||
git branch --list --remote 'origin/*' | cut -d/ -f2
|
git branch --list --remote 'origin/*' | cut -d/ -f2
|
||||||
|
|
||||||
@@ -45,7 +46,6 @@ git reset --soft HEAD~1 # or `git reset --soft HEAD^`
|
|||||||
git restore --staged '.lefthook-local.yml' # or `git reset HEAD '.lefthook-local.yml'`
|
git restore --staged '.lefthook-local.yml' # or `git reset HEAD '.lefthook-local.yml'`
|
||||||
git commit -c ORIG_HEAD
|
git commit -c ORIG_HEAD
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Change the default branch from 'master' to 'main'.
|
# Change the default branch from 'master' to 'main'.
|
||||||
# --------------------------------------
|
# --------------------------------------
|
||||||
@@ -67,7 +67,6 @@ git symbolic-ref 'refs/remotes/origin/HEAD' 'refs/remotes/origin/main'
|
|||||||
# delete the master branch on the remote
|
# delete the master branch on the remote
|
||||||
git push origin --delete 'master'
|
git push origin --delete 'master'
|
||||||
|
|
||||||
|
|
||||||
# create patches from the last commit
|
# create patches from the last commit
|
||||||
git format-patch -n HEAD^
|
git format-patch -n HEAD^
|
||||||
git format-patch HEAD^ -o './patchfile.patch'
|
git format-patch HEAD^ -o './patchfile.patch'
|
||||||
@@ -75,3 +74,30 @@ git format-patch HEAD~1 --stdout
|
|||||||
|
|
||||||
# create patches from specific commits
|
# create patches from specific commits
|
||||||
git format-patch -1 '3918a1d036e74d47a5c830e4bbabba6f507162b1'
|
git format-patch -1 '3918a1d036e74d47a5c830e4bbabba6f507162b1'
|
||||||
|
|
||||||
|
git-all () {
|
||||||
|
[[ -n $DEBUG ]] && set -o xtrace
|
||||||
|
|
||||||
|
local COMMAND
|
||||||
|
local FOLDERS=()
|
||||||
|
for (( I = $# ; I >= 0 ; I-- )); do
|
||||||
|
if [[ -d ${@[$I]} ]]; then
|
||||||
|
FOLDERS+=${@[$I]}
|
||||||
|
else
|
||||||
|
COMMAND="${@[1,-$((${#FOLDERS}+1))]}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [[ -z "$COMMAND" ]]; then
|
||||||
|
echo "error: no command given" >&2
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
local REPOSITORIES=( $(find ${FOLDERS[@]:-'.'} -type d -name .git -exec dirname '{}' \;) )
|
||||||
|
|
||||||
|
parallel --color-failed --tagstring "{/}" "git -C {} $COMMAND" ::: ${REPOSITORIES[@]}
|
||||||
|
# echo -n ${REPOSITORIES[@]} | xargs -d ' ' -tP 0 -I git -C "{}" $(echo ${COMMAND[@]}) # xargs, linux
|
||||||
|
# echo -n ${REPOSITORIES[@]} | xargs -n 1 -P 0 -I {} git -C "{}" $(echo ${COMMAND[@]}) # xargs, osx
|
||||||
|
# for REPOSITORY in ${REPOSITORIES[@]}; do echo -e "\n\n---\n${REPOSITORY}"; git -C "$REPOSITORY" "$COMMAND"; done
|
||||||
|
|
||||||
|
[[ -n $DEBUG ]] && set +o xtrace
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user