2 Commits

Author SHA1 Message Date
rkiel
a934046340 this-is-a-test: another test 2018-02-08 21:54:32 -05:00
rkiel
29bc32edd9 this-is-a-test: test 2018-02-08 21:53:20 -05:00
37 changed files with 1144 additions and 3140 deletions

1
.gitignore vendored
View File

@@ -1 +0,0 @@
node_modules

View File

@@ -4,97 +4,76 @@
### Usage
This feature branch utility is built to work with a set of standard branches (`develop`,`main`,`master`,`release`).
These are the starting point branches from which you can create feature branches.
It is assumed that your starting point branch exists both locally and remotely.
This utility is built around the standard branch `master` and branches for releases that follow the format of MAJOR.MINOR.PATCH.
You can override the default set of standard branches by incorporating a `.git-utilities-rc` file (JSON) into your project repository.
Branch names should be limited to a single word.
Feature branches have specific format: USER-BASE-FEATURE.
```json
{
"branches": ["develop", "test", "production"]
}
```
Feature branch names have a specific format: USER-BRANCH-DESCRIPTION.
- USER is the owner of the feature branch and is specified by either the FEATURE_USER or USER environment variables. This should prevent any feature branch name conflicts and make it easier to know who to talk to about deleting old/unused feature branches.
- BRANCH is the standard branch from which the feature branch was started
- DESCRIPTION is a series of one or more words which describe the feature. The description will be prepended to all commit messages.
* USER is the username as specified by the USER environment variable
* BASE is the standard branch or release branch to base the feature branch on
* FEATURE is the name of the feature
#### Start
To start a new feature, checkout one of the standard branches.
Use the `start` subcommand followed by a short series of words to describe the feature.
For example, use a bug number and a short phrase as the description.
To start a new feature, go to the standard branch or a release branch.
```
git checkout develop
feature start 4365 update help
git checkout master
```
In this example, user `bob` will create a new branch called `bob-develop-4365-update-help`.
If you start with a branch other than one of the standard branches you will get an error.
For example,
Use the `start` subcommand with a feature name.
```
git checkout hotfixes
feature start 4365 update help
ERROR: invalid base branch. must be one of: develop, main, master, release
feature start my new feature
```
For example, a new branch will be created called `rkiel-master-my-new-feature`
#### Commit
Use the `commit` subcommand to make it easier to write commit messages.
No need to specify the `-m` parameter or wrapping the message in quotes.
Of course, if you forget and pass in `-m` anyway, it will be ignore it.
The feature branch description will be prepended to your commit message.
If you forget and pass in `-m` anyway, it will ignore it.
For example,
```
feature commit corrected spelling mistakes
feature commit this is a sample commit message
feature commit -m this is a sample commit message
```
will generate the following commit message:
generates the command `git commit -m "this is a sample commit message"`.
The commit message will be prepended with the feature name. For example,
```
4365-update-help: corrected spelling mistakes
my-feature-name: this is a sample commit message
```
If you need to by-pass any git pre-commit hooks, you can use the `-f` option to force the commit.
This will invoke the commit with the `--no-verify` option.
It will also add `(no-verify)` to the end of your commit message. For example,
```
feature commit -f corrected spelling mistakes
feature commit -f this is a sample commit message
feature commit -m this is a sample commit message -f
```
will generate the following commit message:
generates the command `git commit -m "this is a sample commit message (no-verify)" --no-verify`.
```
4365-update-help: corrected spelling mistakes (no-verify)
```
#### Rebase
Use the `rebase` subcommand to pull down any changes from the standard branch and then rebase with your feature branch changes.
In addition, a backup copy of your feature changes will be pushed out to `origin`.
This remote backup branch should NEVER be used to collaborate with others.
It is just a personal backup and will be deleted and recreated with each `rebase`.
This backup should not be used to collaborate with others. It is just a personal backup and will be deleted and recreated with each `rebase`.
```
feature rebase
```
For example, the `bob-develop-4365-update-help` branch will be pushed out to `origin`.
For example, `rkiel-master-my-new-feature` will be pushed out to `origin`.
#### Merge
Use the `merge` subcommand to merge your feature branch changes to the standard branch.
A `rebase` will be performed automatically before the merge.
```
feature merge
@@ -115,14 +94,11 @@ feature end
Use the `trash` subcommand to forcibly close out the feature.
The standard branch will be checkout and the local feature branch will be forcibly deleted.
Make sure that your changes have been merged because they will be lost.
If there is a backup copy on `origin`, it will also be removed.
As a safety precaution, you must supply the name of the local feature branch on the command line as
a confirmation. This will hopefully protect you from accidentally running `feature trash` when you meant `feature end`.
WARNING: Make sure that your changes have been merged because they will be lost.
For example,
You must supply the name of the local feature branch on the command line as
a confirmation.
```
feature trash bob-develop-4365-update-help
feature trash local-branch-confirmation
```

View File

@@ -1,21 +0,0 @@
MIT License
Copyright (c) 2018 Robert Kiel
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -4,25 +4,25 @@ This is a collection of simple command-line scripts, bash aliases, and bash util
The command-line scripts include:
- [feature](FEATURE.md) - make working with feature branches easier
- [release](RELEASE.md)- make working with release branches and tags easier (DEPRECATED)
- [xgrep](XGREP.md)- make using `git-grep` easier
- [xfind](XFIND.md)- make using `find` easier
* [feature](FEATURE.md) - make working with feature branches easier
* [release](RELEASE.md)- make working with release branches and tags easier
* [xgrep](XGREP.md)- make using `git-grep` easier
The command-line scripts are written in Ruby 2.x using just the standard libraries and do not require any gems to be installed.
For OS X users, these should just work out-of-box.
The `bash` utilities come directly from the [git source contrib](https://github.com/git/git/tree/master/contrib) and include:
- support for [tab completion](https://github.com/git/git/tree/master/contrib/completion/git-completion.bash)
- support for repository status in your [shell prompt](https://github.com/git/git/tree/master/contrib/completion/git-prompt.sh)
* support for [tab completion](https://github.com/git/git/tree/master/contrib/completion/git-completion.bash)
* support for repository status in your [shell prompt](https://github.com/git/git/tree/master/contrib/completion/git-prompt.sh)
## Installation
Clone the repository
```
mkdir -p ~/GitHub/rkiel && cd $_
mkdir -p ~/GitHub/rkiel
cd ~/GitHub/rkiel
git clone https://github.com/rkiel/git-utilities.git
```
@@ -30,12 +30,11 @@ To update your `.bash_profile` and `.bashrc`.
```
cd ~/GitHub/rkiel/git-utilities
./install/bin/setup $USER
./install/bin/setup --user rkiel
```
## Documention
- [See feature](FEATURE.md)
- [See release](RELEASE.md) (DEPRECATED)
- [See xgrep](XGREP.md)
- [See xfind](XFIND.md)
* [See feature](FEATURE.md)
* [See release](RELEASE.md)
* [See xgrep](XGREP.md)

View File

@@ -2,8 +2,6 @@
## Release
NOTE: This command is DEPRECATED.
`release` is a command line utility to make working with releases easier. Releases are built and managed using branches and tags.
Official release versions are tagged using a simplified [Semantic Versioning](http://semver.org/) format. The tags start with the letter `v` followed by MAJOR.MINOR.PATCH.
@@ -53,7 +51,6 @@ The `version` specified must be an existing official release version. The `major
git checkout master
release start patch from 1.0.0
```
or
```bash

View File

@@ -1,15 +0,0 @@
[<<back](README.md)
## Xfind utility
This utility makes it easier to use find.
```bash
Usage: xfind options term(s)
-d, --[no-]debug
-n NAME include NAME
-N NAME exclude NAME
-p PATH include PATH
-P PATH exclude PATH
-h, --help
```

View File

@@ -3,15 +3,3 @@
## Xgrep utility
This utility makes it easier to use git-grep.
```bash
Usage: xgrep options term(s)
-d, --[no-]debug
-f, --file
-i, --invert
-p, --include-path PATHS
-P, --exclude-path PATHS
-t, --include-type TYPES
-T, --exclude-type TYPES
-h, --help
```

View File

@@ -1,9 +0,0 @@
#!/usr/bin/env node
const commander = require("commander");
const program = new commander.Command();
program
.command("start feature-words", "start a new feature")
.command("end", "end a feature")
.parse(process.argv);

View File

@@ -1,33 +0,0 @@
#!/usr/bin/env node
const _ = require("lodash");
const path = x => require("../" + x);
const git = path("js/git");
const shell = path("js/shell");
const commander = path("js/commander");
const validate = path("js/validate");
function endFeatureBranch(dp) {
const cmds = [
`git checkout ${dp.branch.standard}`,
`git branch -d ${dp.branch.current}`
];
const remoteBranch = _.get(dp, "branch.remote", false);
if (remoteBranch) {
cmds.push(`git push origin :${remoteBranch}`);
}
return shell.pipeline(cmds);
}
commander
.start()
.then(git.gather)
.then(commander.echo)
// .then(git.setCurrentBranch)
// .then(git.parseCurrentBranch)
// .then(validate.mustBeFeatureBranch)
// .then(git.setStandardBranch)
// .then(git.isBranchRemote)
// .then(endFeatureBranch)
.catch(err => console.error(err));

View File

@@ -1,28 +0,0 @@
#!/usr/bin/env node
const _ = require("lodash");
const path = x => require("../" + x);
const git = path("js/git");
const shell = path("js/shell");
const commander = path("js/commander");
const validate = path("js/validate");
function createFeatureBranch(dp) {
return shell.pipeline([
"git fetch --prune --prune-tags --tags origin",
`git merge origin/${dp.branch.current}`,
"git push",
`git checkout -b ${dp.branch.feature}`,
`git push -u origin ${dp.branch.feature}`
]);
}
commander
.start()
.then(git.setCurrentBranch)
.then(validate.currentIsStandardBranch)
.then(git.setFeatureBranch)
.then(validate.featureIsNotStandardBranch)
.then(createFeatureBranch)
.catch(err => console.error(err));

View File

@@ -1,17 +0,0 @@
#!/usr/bin/env ruby
require_relative '../lib/xfind/commander'
if File.exist? './.xfind'
project_argv = File.read('./.xfind').split(/\s/).reject { |x| x.strip == "" }
argv = project_argv + ARGV
else
argv = ARGV
end
commander = Xfind::Commander.new(argv)
if commander.valid?
commander.execute
else
commander.help
end

View File

@@ -1,14 +0,0 @@
export EDITOR=vim
# generated by ./bin/generate-bash-prompt
# export PS1='[\[\e[0;35m\]\u@\h\[\e[0m\] \[\e[1;34m\]\W\[\e[0m\]]\$ '
export PS1='[\[\e[0;35m\]\u@\h\[\e[0m\] \[\e[1;34m\]\W\[\e[0;32m\]$(__git_ps1 " %s")\[\e[0m\]]\$ '
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
LOCALS=~/.bashrc_local
if [ -f $LOCALS ]; then
source $LOCALS
fi

View File

@@ -1,30 +1,30 @@
alias h='history'
alias lsa='ls -la'
alias lsl='ls -l'
alias more='less -RX'
alias sl='ls'
alias a='git add'
alias b="git branch"
# alias add="git add"
alias branch="git branch"
alias c='feature commit'
alias checkout="git checkout"
alias co='git checkout'
alias d='clear; git diff -w'
alias l="git log --graph --date=short --pretty=format:'%C(yellow)%h %C(white)%ad %C(black)[%C(green)%an%C(black)] %C(blue)%s%C(yellow)%d'"
alias log='git log -w -u'
alias m='feature merge'
alias master="git checkout master"
# alias commit="feature commit"
alias pop="git stash pop --index"
alias pull="git pull"
alias push="git push"
alias master="git checkout master"
# alias develop="git checkout develop"
# alias diff="clear; git diff -w"
# alias linuxdiff="/usr/bin/diff"
# alias sysdiff="/usr/bin/diff"
# alias log="git log --graph --decorate --abbrev-commit --pretty=oneline"
# alias log="git log --graph --date=short --pretty=format:'%C(yellow)%h %C(white)%ad %C(black)[%C(green)%an%C(black)] %C(blue)%s%C(yellow)%d'"
alias stash="git stash save"
# alias status="git status; echo; echo STASH:; git stash list; echo"
alias a='git add'
alias c='feature commit'
alias co='git checkout'
alias d='clear; git diff -w'
alias l="git log --graph --date=short --pretty=format:'%C(yellow)%h %C(white)%ad %C(black)[%C(green)%an%C(black)] %C(blue)%s%C(yellow)%d'"
alias m='feature merge'
alias r='feature rebase'
alias s='git status; echo; echo STASH:; git stash list; echo'
alias show='git show -w'
alias stash="git stash save"
alias x='xgrep'
alias sfind='find . -not \( -type d -name .git -prune \) -not \( -type d -name node_modes -prune \) -and \( -type f \)|sort -f'
alias sgrep='find . -not \( -type d -name .git -prune \) -not \( -type d -name node_modes -prune \) -and \( -type f \)|sort -f|xargs grep --color=always'
alias cgrep='grep --color=always'
@@ -39,9 +39,14 @@ function get_feature_commands()
fi
}
complete -F get_feature_commands feature
LOCALS=~/.bashrc_locals
if [ -f $LOCALS ]; then
source $LOCALS
function get_release_commands()
{
if [ -z $2 ] ; then
COMPREPLY=(`release tab`)
else
COMPREPLY=(`release tab $2`)
fi
}
complete -F get_feature_commands feature
complete -F get_release_commands release

File diff suppressed because it is too large Load Diff

View File

@@ -1,293 +0,0 @@
#compdef git gitk
# zsh completion wrapper for git
#
# Copyright (c) 2012-2020 Felipe Contreras <felipe.contreras@gmail.com>
#
# The recommended way to install this script is to make a copy of it as a
# file named '_git' inside any directory in your fpath.
#
# For example, create a directory '~/.zsh/', copy this file to '~/.zsh/_git',
# and then add the following to your ~/.zshrc file:
#
# fpath=(~/.zsh $fpath)
#
# You need git's bash completion script installed. By default bash-completion's
# location will be used (e.g. pkg-config --variable=completionsdir bash-completion).
#
# If your bash completion script is somewhere else, you can specify the
# location in your ~/.zshrc:
#
# zstyle ':completion:*:*:git:*' script ~/.git-completion.bash
#
zstyle -T ':completion:*:*:git:*' tag-order && \
zstyle ':completion:*:*:git:*' tag-order 'common-commands'
zstyle -s ":completion:*:*:git:*" script script
if [ -z "$script" ]; then
local -a locations
local e bash_completion
bash_completion=$(pkg-config --variable=completionsdir bash-completion 2>/dev/null) ||
bash_completion='/usr/share/bash-completion/completions/'
locations=(
"$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
"$HOME/.local/share/bash-completion/completions/git"
"$bash_completion/git"
'/etc/bash_completion.d/git' # old debian
)
for e in $locations; do
test -f $e && script="$e" && break
done
fi
local old_complete="$functions[complete]"
functions[complete]=:
GIT_SOURCING_ZSH_COMPLETION=y . "$script"
functions[complete]="$old_complete"
__gitcomp ()
{
emulate -L zsh
local cur_="${3-$cur}"
case "$cur_" in
--*=)
;;
--no-*)
local c IFS=$' \t\n'
local -a array
for c in ${=1}; do
if [[ $c == "--" ]]; then
continue
fi
c="$c${4-}"
case $c in
--*=|*.) ;;
*) c="$c " ;;
esac
array+=("$c")
done
compset -P '*[=:]'
compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
;;
*)
local c IFS=$' \t\n'
local -a array
for c in ${=1}; do
if [[ $c == "--" ]]; then
c="--no-...${4-}"
array+=("$c ")
break
fi
c="$c${4-}"
case $c in
--*=|*.) ;;
*) c="$c " ;;
esac
array+=("$c")
done
compset -P '*[=:]'
compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
;;
esac
}
__gitcomp_direct ()
{
emulate -L zsh
compset -P '*[=:]'
compadd -Q -S '' -- ${(f)1} && _ret=0
}
__gitcomp_nl ()
{
emulate -L zsh
compset -P '*[=:]'
compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0
}
__gitcomp_file ()
{
emulate -L zsh
compadd -f -p "${2-}" -- ${(f)1} && _ret=0
}
__gitcomp_direct_append ()
{
__gitcomp_direct "$@"
}
__gitcomp_nl_append ()
{
__gitcomp_nl "$@"
}
__gitcomp_file_direct ()
{
__gitcomp_file "$1" ""
}
_git_zsh ()
{
__gitcomp "v1.1"
}
__git_complete_command ()
{
emulate -L zsh
local command="$1"
local completion_func="_git_${command//-/_}"
if (( $+functions[$completion_func] )); then
emulate ksh -c $completion_func
return 0
else
return 1
fi
}
__git_zsh_bash_func ()
{
emulate -L ksh
local command=$1
__git_complete_command "$command" && return
local expansion=$(__git_aliased_command "$command")
if [ -n "$expansion" ]; then
words[1]=$expansion
__git_complete_command "$expansion"
fi
}
__git_zsh_cmd_common ()
{
local -a list
list=(
add:'add file contents to the index'
bisect:'find by binary search the change that introduced a bug'
branch:'list, create, or delete branches'
checkout:'checkout a branch or paths to the working tree'
clone:'clone a repository into a new directory'
commit:'record changes to the repository'
diff:'show changes between commits, commit and working tree, etc'
fetch:'download objects and refs from another repository'
grep:'print lines matching a pattern'
init:'create an empty Git repository or reinitialize an existing one'
log:'show commit logs'
merge:'join two or more development histories together'
mv:'move or rename a file, a directory, or a symlink'
pull:'fetch from and merge with another repository or a local branch'
push:'update remote refs along with associated objects'
rebase:'forward-port local commits to the updated upstream head'
reset:'reset current HEAD to the specified state'
restore:'restore working tree files'
rm:'remove files from the working tree and from the index'
show:'show various types of objects'
status:'show the working tree status'
switch:'switch branches'
tag:'create, list, delete or verify a tag object signed with GPG')
_describe -t common-commands 'common commands' list && _ret=0
}
__git_zsh_cmd_alias ()
{
local -a list
list=(${${(0)"$(git config -z --get-regexp '^alias\.*')"}#alias.})
list=(${(f)"$(printf "%s:alias for '%s'\n" ${(f@)list})"})
_describe -t alias-commands 'aliases' list && _ret=0
}
__git_zsh_cmd_all ()
{
local -a list
emulate ksh -c __git_compute_all_commands
list=( ${=__git_all_commands} )
_describe -t all-commands 'all commands' list && _ret=0
}
__git_zsh_main ()
{
local curcontext="$curcontext" state state_descr line
typeset -A opt_args
local -a orig_words
orig_words=( ${words[@]} )
_arguments -C \
'(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \
'(-p --paginate)--no-pager[do not pipe git output into a pager]' \
'--git-dir=-[set the path to the repository]: :_directories' \
'--bare[treat the repository as a bare repository]' \
'(- :)--version[prints the git suite version]' \
'--exec-path=-[path to where your core git programs are installed]:: :_directories' \
'--html-path[print the path where git''s HTML documentation is installed]' \
'--info-path[print the path where the Info files are installed]' \
'--man-path[print the manpath (see `man(1)`) for the man pages]' \
'--work-tree=-[set the path to the working tree]: :_directories' \
'--namespace=-[set the git namespace]' \
'--no-replace-objects[do not use replacement refs to replace git objects]' \
'(- :)--help[prints the synopsis and a list of the most commonly used commands]: :->arg' \
'(-): :->command' \
'(-)*:: :->arg' && return
case $state in
(command)
_tags common-commands alias-commands all-commands
while _tags; do
_requested common-commands && __git_zsh_cmd_common
_requested alias-commands && __git_zsh_cmd_alias
_requested all-commands && __git_zsh_cmd_all
let _ret || break
done
;;
(arg)
local command="${words[1]}" __git_dir
if (( $+opt_args[--bare] )); then
__git_dir='.'
else
__git_dir=${opt_args[--git-dir]}
fi
(( $+opt_args[--help] )) && command='help'
words=( ${orig_words[@]} )
__git_zsh_bash_func $command
;;
esac
}
_git ()
{
local _ret=1
local cur cword prev
cur=${words[CURRENT]}
prev=${words[CURRENT-1]}
let cword=CURRENT-1
if (( $+functions[__${service}_zsh_main] )); then
__${service}_zsh_main
elif (( $+functions[__${service}_main] )); then
emulate ksh -c __${service}_main
elif (( $+functions[_${service}] )); then
emulate ksh -c _${service}
elif (( $+functions[_${service//-/_}] )); then
emulate ksh -c _${service//-/_}
fi
let _ret && _default && _ret=0
return _ret
}
_git

View File

@@ -66,19 +66,6 @@
# git always compare HEAD to @{upstream}
# svn always compare HEAD to your SVN upstream
#
# You can change the separator between the branch name and the above
# state symbols by setting GIT_PS1_STATESEPARATOR. The default separator
# is SP.
#
# When there is an in-progress operation such as a merge, rebase,
# revert, cherry-pick, or bisect, the prompt will include information
# related to the operation, often in the form "|<OPERATION-NAME>".
#
# When the repository has a sparse-checkout, a notification of the form
# "|SPARSE" will be included in the prompt. This can be shortened to a
# single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted
# by setting GIT_PS1_OMITSPARSESTATE.
#
# By default, __git_ps1 will compare HEAD to your SVN upstream if it can
# find one, or @{upstream} otherwise. Once you have set
# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
@@ -91,14 +78,12 @@
# contains relative to newer annotated tag (v1.6.3.2~35)
# branch relative to newer tag or branch (master~4)
# describe relative to older annotated tag (v1.6.3.1-13-gdd42c2f)
# tag relative to any older tag (v1.6.3.1-13-gdd42c2f)
# default exactly matching tag
#
# If you would like a colored hint about the current dirty state, set
# GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
# the colored output of "git status -sb" and are available only when
# using __git_ps1 for PROMPT_COMMAND or precmd in Bash,
# but always available in Zsh.
# using __git_ps1 for PROMPT_COMMAND or precmd.
#
# If you would like __git_ps1 to do nothing in the case when the current
# directory is set up to be ignored by git, then set
@@ -138,7 +123,6 @@ __git_ps1_show_upstream ()
done <<< "$output"
# parse configuration values
local option
for option in ${GIT_PS1_SHOWUPSTREAM}; do
case "$option" in
git|svn) upstream="$option" ;;
@@ -289,43 +273,11 @@ __git_ps1_colorize_gitstring ()
r="$c_clear$r"
}
# Helper function to read the first line of a file into a variable.
# __git_eread requires 2 arguments, the file path and the name of the
# variable, in that order.
__git_eread ()
{
test -r "$1" && IFS=$'\r\n' read "$2" <"$1"
}
# see if a cherry-pick or revert is in progress, if the user has committed a
# conflict resolution with 'git commit' in the middle of a sequence of picks or
# reverts then CHERRY_PICK_HEAD/REVERT_HEAD will not exist so we have to read
# the todo file.
__git_sequencer_status ()
{
local todo
if test -f "$g/CHERRY_PICK_HEAD"
then
r="|CHERRY-PICKING"
return 0;
elif test -f "$g/REVERT_HEAD"
then
r="|REVERTING"
return 0;
elif __git_eread "$g/sequencer/todo" todo
then
case "$todo" in
p[\ \ ]|pick[\ \ ]*)
r="|CHERRY-PICKING"
return 0
;;
revert[\ \ ]*)
r="|REVERTING"
return 0
;;
esac
fi
return 1
local f="$1"
shift
test -r "$f" && read "$@" <"$f"
}
# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
@@ -399,8 +351,8 @@ __git_ps1 ()
# incorrect.)
#
local ps1_expanded=yes
[ -z "${ZSH_VERSION-}" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no
[ -z "${BASH_VERSION-}" ] || shopt -q promptvars || ps1_expanded=no
[ -z "$ZSH_VERSION" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no
[ -z "$BASH_VERSION" ] || shopt -q promptvars || ps1_expanded=no
local repo_info rev_parse_exit_code
repo_info="$(git rev-parse --git-dir --is-inside-git-dir \
@@ -412,7 +364,7 @@ __git_ps1 ()
return $exit
fi
local short_sha=""
local short_sha
if [ "$rev_parse_exit_code" = "0" ]; then
short_sha="${repo_info##*$'\n'}"
repo_info="${repo_info%$'\n'*}"
@@ -432,13 +384,6 @@ __git_ps1 ()
return $exit
fi
local sparse=""
if [ -z "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
[ -z "${GIT_PS1_OMITSPARSESTATE}" ] &&
[ "$(git config --bool core.sparseCheckout)" = "true" ]; then
sparse="|SPARSE"
fi
local r=""
local b=""
local step=""
@@ -447,7 +392,11 @@ __git_ps1 ()
__git_eread "$g/rebase-merge/head-name" b
__git_eread "$g/rebase-merge/msgnum" step
__git_eread "$g/rebase-merge/end" total
r="|REBASE"
if [ -f "$g/rebase-merge/interactive" ]; then
r="|REBASE-i"
else
r="|REBASE-m"
fi
else
if [ -d "$g/rebase-apply" ]; then
__git_eread "$g/rebase-apply/next" step
@@ -462,8 +411,10 @@ __git_ps1 ()
fi
elif [ -f "$g/MERGE_HEAD" ]; then
r="|MERGING"
elif __git_sequencer_status; then
:
elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
r="|CHERRY-PICKING"
elif [ -f "$g/REVERT_HEAD" ]; then
r="|REVERTING"
elif [ -f "$g/BISECT_LOG" ]; then
r="|BISECTING"
fi
@@ -488,8 +439,6 @@ __git_ps1 ()
git describe --contains HEAD ;;
(branch)
git describe --contains --all HEAD ;;
(tag)
git describe --tags HEAD ;;
(describe)
git describe HEAD ;;
(* | default)
@@ -510,7 +459,6 @@ __git_ps1 ()
local i=""
local s=""
local u=""
local h=""
local c=""
local p=""
@@ -524,9 +472,10 @@ __git_ps1 ()
if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&
[ "$(git config --bool bash.showDirtyState)" != "false" ]
then
git diff --no-ext-diff --quiet || w="*"
git diff --no-ext-diff --cached --quiet || i="+"
if [ -z "$short_sha" ] && [ -z "$i" ]; then
git diff --no-ext-diff --quiet --exit-code || w="*"
if [ -n "$short_sha" ]; then
git diff-index --cached --quiet HEAD -- || i="+"
else
i="#"
fi
fi
@@ -538,16 +487,11 @@ __git_ps1 ()
if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
[ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
git ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- ':/*' >/dev/null 2>/dev/null
git ls-files --others --exclude-standard --error-unmatch -- ':/*' >/dev/null 2>/dev/null
then
u="%${ZSH_VERSION+%}"
fi
if [ -n "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
[ "$(git config --bool core.sparseCheckout)" = "true" ]; then
h="?"
fi
if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
__git_ps1_show_upstream
fi
@@ -555,12 +499,10 @@ __git_ps1 ()
local z="${GIT_PS1_STATESEPARATOR-" "}"
# NO color option unless in PROMPT_COMMAND mode or it's Zsh
if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
if [ $pcmode = yes ] || [ -n "${ZSH_VERSION-}" ]; then
# NO color option unless in PROMPT_COMMAND mode
if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
__git_ps1_colorize_gitstring
fi
fi
b=${b##refs/heads/}
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
@@ -568,8 +510,8 @@ __git_ps1 ()
b="\${__git_ps1_branch_name}"
fi
local f="$h$w$i$s$u"
local gitstring="$c$b${f:+$z$f}${sparse}$r$p"
local f="$w$i$s$u"
local gitstring="$c$b${f:+$z$f}$r$p"
if [ $pcmode = yes ]; then
if [ "${__git_printf_supports_v-}" != yes ]; then

View File

@@ -1,15 +0,0 @@
export EDITOR=vim
autoload -Uz vcs_info
precmd_vcs_info() { vcs_info }
precmd_functions+=( precmd_vcs_info )
setopt prompt_subst
zstyle ':vcs_info:git:*' formats '%b'
# generated by ./bin/generate-bash-prompt
export PS1='[%B%F{magenta}%n@%m%f%b %B%F{blue}%1d%f%b %B%F{green}'\$vcs_info_msg_0_'%f%b]$ '
LOCALS=~/.zprofile_locals
if [ -f $LOCALS ]; then
source $LOCALS
fi

View File

@@ -1,61 +0,0 @@
GIT_UTILITIES_BIN=~/GitHub/rkiel/git-utilities/bin
export PATH=${GIT_UTILITIES_BIN}:$PATH
export EDITOR=vim
autoload -Uz vcs_info
precmd_vcs_info() { vcs_info }
precmd_functions+=( precmd_vcs_info )
setopt prompt_subst
zstyle ':vcs_info:git:*' formats '%b'
# generated by ./bin/generate-bash-prompt
export PS1='[%B%F{magenta}%n@%m%f%b %B%F{blue}%1d%f%b %B%F{green}'\$vcs_info_msg_0_'%f%b]$ '
alias h='history'
alias lsa='ls -la'
alias lsl='ls -l'
alias more='less -RX'
alias sl='ls'
alias a='git add'
alias b="git branch"
alias branch="git branch"
alias c='feature commit'
alias checkout="git checkout"
alias co='git checkout'
alias d='clear; git diff -w'
alias l="git log --graph --date=short --pretty=format:'%C(yellow)%h %C(white)%ad %C(black)[%C(green)%an%C(black)] %C(blue)%s%C(yellow)%d'"
alias log='git log -w -u'
alias m='feature merge'
alias master="git checkout master"
alias pop="git stash pop --index"
alias pull="git pull"
alias push="git push"
alias r='feature rebase'
alias s='git status; echo; echo STASH:; git stash list; echo'
alias show='git show -w'
alias stash="git stash save"
alias x='xgrep'
alias sfind='find . -not \( -type d -name .git -prune \) -not \( -type d -name node_modes -prune \) -and \( -type f \)|sort -f'
alias sgrep='find . -not \( -type d -name .git -prune \) -not \( -type d -name node_modes -prune \) -and \( -type f \)|sort -f|xargs grep --color=always'
alias cgrep='grep --color=always'
alias vgrep='grep -v'
function get_feature_commands()
{
if [ -z $2 ] ; then
COMPREPLY=(`feature tab`)
else
COMPREPLY=(`feature tab $2`)
fi
}
complete -F get_feature_commands feature
LOCALS=~/.zshrc_locals
if [ -f $LOCALS ]; then
source $LOCALS
fi

View File

@@ -1,44 +1,10 @@
REPO="~/GitHub/rkiel/git-utilities"
GIT="~/GitHub/git/git"
#!/usr/bin/env ruby
# mkdir ~/GitHub/git && cd $_
# git clone https://github.com/git/git.git
# cd git
# ls|grep -v contrib|xargs rm -rf
require_relative '../lib/setup/commander'
if [ "$2" == "zsh" ] ; then
# FILE=~/.zprofile
# echo >> $FILE
# if [ ! -z "$1" ] ; then
# echo "export FEATURE_USER=$1" >> $FILE
# fi
# echo "GIT_UTILITIES_BIN=${REPO}/bin" >> $FILE
# echo "export PATH=${GIT_UTILITIES_BIN}:$PATH" >> $FILE
# # echo "source ${REPO}/dotfiles/git-completion.zsh" >> $FILE
# # echo "source ${REPO}/dotfiles/git-prompt.sh" >> $FILE
# echo "source ${REPO}/dotfiles/zprofile" >> $FILE
FILE=~/.zshrc
echo >> $FILE
if [ ! -z "$1" ] ; then
echo "export FEATURE_USER=$1" >> $FILE
fi
echo "GIT_UTILITIES=${REPO}" >> $FILE
echo 'source ${GIT_UTILITIES}/dotfiles/zshrc' >> $FILE
commander = Setup::Commander.new(ARGV)
if commander.valid?
commander.execute
else
FILE=~/.bash_profile
echo >> $FILE
if [ ! -z "$1" ] ; then
echo "export FEATURE_USER=$1" >> $FILE
fi
echo "GIT_UTILITIES=${REPO}" >> $FILE
echo 'export PATH=${GIT_UTILITIES}/bin:$PATH' >> $FILE
echo 'source ${GIT_UTILITIES}/dotfiles/git-completion.bash' >> $FILE
echo 'source ${GIT_UTILITIES}/dotfiles/git-prompt.sh' >> $FILE
echo 'source ${GIT_UTILITIES}/dotfiles/bash_profile' >> $FILE
FILE=~/.bashrc
echo >> $FILE
echo "GIT_UTILITIES=${REPO}" >> $FILE
echo 'source ${GIT_UTILITIES}/dotfiles/bashrc' >> $FILE
fi
commander.help
end

View File

@@ -45,21 +45,27 @@ module Setup
File.open("#{ENV['HOME']}/.bash_profile", "a") do |f|
f.puts
f.puts '#############################################################'
f.puts "# added by ~/GitHub/rkiel/git-utilities/install/bin/setup"
f.puts '#############################################################'
f.puts 'export GIT_UTILITIES_BIN="~/GitHub/rkiel/git-utilities/bin"'
f.puts 'export PATH=${GIT_UTILITIES_BIN}:$PATH'
f.puts 'source ~/GitHub/rkiel/git-utilities/dotfiles/git-completion.bash'
f.puts 'source ~/GitHub/rkiel/git-utilities/dotfiles/git-prompt.sh'
f.puts "export FEATURE_USER=#{options.user}" if options.user
f.puts "export PS1='#{Setup::Prompt.new.generate(options)}'"
f.puts '#############################################################'
f.puts
end
File.open("#{ENV['HOME']}/.bashrc", "a") do |f|
f.puts
f.puts '#############################################################'
f.puts "# added by ~/GitHub/rkiel/git-utilities/install/bin/setup"
f.puts '#############################################################'
f.puts 'source ~/GitHub/rkiel/git-utilities/dotfiles/bashrc'
f.puts '#############################################################'
f.puts
end

View File

@@ -1,18 +0,0 @@
let lib;
// TODO: read from .git-utilities
function standard() {
return ["master", "release", "main", "develop"];
}
function isStandard(b) {
return lib.standard().includes(b);
}
function isNonStandard(b) {
return !lib.isStandard(b);
}
lib = { standard, isStandard, isNonStandard };
module.exports = lib;

View File

@@ -1,45 +0,0 @@
const commander = require("commander");
const program = new commander.Command();
const something = program.parse(process.argv);
let lib;
function args() {
return something.args;
}
function featureName() {
return args().join("-");
}
function parse() {
return { program: something };
}
function prefix() {
return process.env.FEATURE_USER || process.env.USER;
}
function toPromise(dp) {
return Promise.resolve(dp);
}
function echo(dp) {
console.log(JSON.stringify(dp, null, 2));
return dp;
}
function start() {
return toPromise(parse());
}
lib = {
args,
parse,
featureName,
prefix,
start,
echo
};
module.exports = lib;

View File

@@ -1,17 +0,0 @@
const fs = require("fs");
const util = require("util");
let lib;
function exists(path) {
const stat = util.promisify(fs.stat);
return stat(path);
}
function read(path) {
const readFile = util.promisify(fs.readFile);
return readFile(path).then(buffer => buffer.toString("utf-8"));
}
lib = { exists, read };
module.exports = lib;

130
js/git.js
View File

@@ -1,130 +0,0 @@
const _ = require("lodash");
const path = x => require("../" + x);
const commander = path("js/commander");
const immutable = path("js/immutable");
const shell = path("js/shell");
const file = path("js/file");
const branch = path("js/branch");
let lib;
function setBranch(dp, field, branch) {
return immutable.set(dp, `branch.${field}`, branch);
}
function setCurrentBranch(dp) {
return file
.read(".git/HEAD")
.then(contents => contents.split("/"))
.then(parts => _.last(parts))
.then(last => last.trim())
.then(branch => immutable.set(dp, "branch.current", branch));
}
function setStandardAndFeature(dp) {
const current = _.get(dp, "branch.current");
if (branch.isStandard(current)) {
return immutable.set(
immutable.set(dp, "branch.standard", current),
"branch.feature",
false
);
} else {
const parts = current.split("-");
if (
parts.length > 2 &&
commander.prefix() === parts[0] &&
branch.isStandard(parts[1])
) {
return immutable.set(
immutable.set(dp, "branch.standard", parts[1]),
"branch.feature",
current
);
} else {
return immutable.set(
immutable.set(dp, "branch.standard", false),
"branch.feature",
false
);
}
}
}
function setRemote(dp) {
const current = _.get(dp, "branch.current");
if (branch.isStandard(current)) {
return immutable.set(dp, "branch.remote", false);
} else {
return file
.exists(`.git/refs/remotes/origin/${current}`)
.then(() => immutable.set(dp, "branch.remote", current))
.catch(() => immutable.set(dp, "branch.remote", false));
}
}
function gather(dp) {
return file
.exists(".git")
.then(() => ({}))
.then(lib.setCurrentBranch)
.then(lib.setStandardAndFeature)
.then(lib.setRemote)
.catch(() => {
throw "not in GIT_ROOT";
});
}
// function setCurrentBranch(dp) {
// const cmd = "git rev-parse --abbrev-ref HEAD";
//
// return shell.capture(cmd).then(x => immutable.set(dp, "branch.current", x));
// }
function setFeatureBranch(dp) {
const fb = [
commander.prefix(),
dp.branch.current,
commander.featureName()
].join("-");
return immutable.set(dp, "branch.feature", fb);
}
function parseCurrentBranch(dp) {
const parts = dp.branch.current.split("-");
return immutable.set(dp, "branch.parts", parts);
}
function setStandardBranch(dp) {
const parts = _.get(dp, "branch.parts", []);
return immutable.set(dp, "branch.standard", parts[1]);
}
function isBranchRemote(dp) {
const branch = _.get(dp, "branch.current");
const cmd = `git branch -r|grep origin|grep -v 'HEAD'|grep ${branch}`;
return shell
.capture(cmd)
.then(x => x.trim())
.then(x =>
x === ""
? immutable.set(dp, "branch.remote", false)
: immutable.set(dp, "branch.remote", branch)
);
}
lib = {
//setCurrentBranch,
setFeatureBranch,
setStandardBranch,
parseCurrentBranch,
isBranchRemote,
gather,
setStandardAndFeature,
setCurrentBranch,
setRemote,
setBranch: _.curry(setBranch)
};
module.exports = lib;

View File

@@ -1,13 +0,0 @@
const _ = require("lodash");
let lib;
function set(dp, path, value) {
return _.set(_.assign({}, dp), path, value);
}
lib = {
set
};
module.exports = lib;

View File

@@ -1,47 +0,0 @@
const _ = require("lodash");
const util = require("util");
const child_process = require("child_process");
const exec = util.promisify(child_process.exec);
let lib;
function run(cmd) {
return exec(cmd);
}
function capture(cmd) {
return lib.run(cmd).then(x => x.stdout.trim());
}
function _something(dp) {
return function() {
return dp;
};
}
function something(cmd, dp) {
return lib.run(cmd).then(lib._something(dp));
}
function pipeline(cmds) {
return _.reduce(
cmds,
(accum, elem) => {
return accum
.then(() => console.log())
.then(() => console.log(elem))
.then(() => exec(elem));
},
Promise.resolve({})
).then(() => console.log());
}
lib = {
_something,
run,
capture,
pipeline,
something: _.curry(something)
};
module.exports = lib;

View File

@@ -1,50 +0,0 @@
const path = x => require("../" + x);
const branch = path("js/branch");
const commander = path("js/commander");
let lib;
function currentIsStandardBranch(dp) {
if (branch.isNonStandard(dp.branch.current)) {
const branches = branch
.standard()
.sort()
.join(", ");
throw `ERROR: starting branch must be one of: ${branches}`;
} else {
return dp;
}
}
function featureIsNotStandardBranch(dp) {
if (branch.isStandard(commander.featureName())) {
const branches = branch
.standard()
.sort()
.join(", ");
throw `ERROR: feature branch cannot be any of: ${branches}`;
} else {
return dp;
}
}
function mustBeFeatureBranch(dp) {
const parts = dp.branch.parts;
if (
parts.length > 2 &&
commander.prefix() === parts[0] &&
branch.isStandard(parts[1])
) {
return dp;
} else {
throw `ERROR: ${dp.branch.current} is not a feature branch`;
}
}
lib = {
currentIsStandardBranch,
mustBeFeatureBranch,
featureIsNotStandardBranch
};
module.exports = lib;

View File

@@ -10,7 +10,6 @@ module Feature
:help,
:end,
:rebase,
:republish,
:merge,
:start,
:tab,

View File

@@ -14,27 +14,18 @@ module Feature
def execute
parts = parse_branch(current_branch)
standard_branch = parts[:standard]
feature_branch = current_branch
remote_branch = remote_branch(feature_branch)
if argv.size == 2
merge_to_branch = argv[1]
elsif argv.size == 1
merge_to_branch = parts[:standard]
end
feature_branch = current_branch
error "invalid branch: #{merge_to_branch}" unless standard_branches.include? merge_to_branch or merge_to_branch =~ /\d+\.\d+\.\d+/
# should match rebase
git_fetch
git_rebase ['origin', standard_branch].join('/')
if remote_branch != ""
git_remote_branch_delete feature_branch
end
git_push feature_branch
git_checkout merge_to_branch
git_pull merge_to_branch
git_merge feature_branch
git_push merge_to_branch
git_push_tags

View File

@@ -21,13 +21,16 @@ module Feature
error "USAGE: feature rebase" unless standard_branch
error "invalid feature branch: #{feature_branch}" if standard_branches.include? feature_branch
git_fetch
git_rebase ['origin', standard_branch].join('/')
git_checkout standard_branch
git_pull standard_branch
git_checkout feature_branch
git_rebase standard_branch
if remote_branch != ""
git_remote_branch_delete feature_branch
end
git_push feature_branch
end
end

View File

@@ -1,73 +0,0 @@
require_relative './base'
module Feature
class Republish < Feature::Base
def valid?
argv.size == 1
end
def help
"feature republish"
end
def execute
parts = parse_branch(current_branch)
standard_branch = parts[:standard]
feature_branch = current_branch
remote_branch = remote_branch(feature_branch)
error "USAGE: feature republish" unless standard_branch
error "invalid feature branch: #{feature_branch}" if standard_branches.include? feature_branch
git_checkout standard_branch
git_fetch
git_pull standard_branch
git_checkout feature_branch
git_rebase standard_branch
if remote_branch != ""
git_remote_branch_delete feature_branch
end
git_push feature_branch
version = package_json_version('0.0.0-0')
tags = `git tag -l`.strip.split("\n").select {|x| x.start_with? version}
tags = tags.map {|x| x =~ /^\d+.\d+.\d+[-]\d+$/ ? x.split('-').last : '0'}
tags = tags.map {|x| x.to_i }
tags << 0
new_number = tags.uniq.max + 1
new_tag = "#{version}-#{new_number}"
git_local_tag new_tag
git_push_tags
data = republish_push
data['push_to'].each do |repo|
puts "updating #{repo}"
repo_dir = File.join(Dir.pwd, '..', repo)
json = package_json_file repo_dir
update_tag data['name'], json['dependencies'], new_tag
update_tag data['name'], json['devDependencies'], new_tag
save_package_json_file json, repo_dir
end
end
private
def update_tag name, dependencies, new_tag
dependencies.keys.each do |key|
if key == name
value = dependencies[key]
parts = value.split('#')
dependencies[key] = [parts.first,'#',new_tag].join
end
end
end
end
end

View File

@@ -17,15 +17,14 @@ module Feature
feature_name = feature_words.join('-')
feature_branch = "#{ENV['FEATURE_USER']||ENV['USER']}-#{current_branch}-#{feature_name}"
error "invalid base branch. must be one of: #{standard_branches.sort.join(', ')}" unless standard_branches.include? current_branch or current_branch =~ /\d+\.\d+\.\d+/
error "invalid base branch: #{current_branch}" unless standard_branches.include? current_branch or current_branch =~ /\d+\.\d+\.\d+/
error "invalid feature branch: #{feature_name}" if standard_branches.include? feature_name
git_fetch
git_merge ['origin', current_branch].join('/')
git_branch feature_branch
git_checkout feature_branch
git_pull current_branch
git_local_branch_create feature_branch
git_push feature_branch
end
end

View File

@@ -10,14 +10,7 @@ module Shared
end
def standard_branches
defaults = ['master','release','main','develop']
dot_file = ".git-utilities-rc"
if File.exist? dot_file
json = JSON.parse(File.read(dot_file))
json['branches'] or defaults
else
defaults
end
['master','release']
end
def version_pattern

View File

@@ -1,5 +1,4 @@
require 'json'
require 'yaml'
module Shared
@@ -33,42 +32,6 @@ module Shared
end
end
def package_json_version (default_value)
if File.exist? 'package.json'
package_json = File.read('package.json')
json = JSON.parse(package_json)
json['version']
else
default_value
end
end
def package_json_file (dir = '.')
name = File.join(dir, 'package.json')
if File.exist? name
package_json = File.read(name)
JSON.parse(package_json)
else
{}
end
end
def save_package_json_file (json, dir = '.')
name = File.join(dir, 'package.json')
if File.exist? name
File.write(name, JSON.pretty_generate(json))
end
end
def republish_push
name = '.republish_push.yml'
if File.exist? name
contents = YAML.load_file(name)
else
{ "push_to" => [] }
end
end
def git_add (path)
run_cmd "git add #{path}"
end
@@ -136,10 +99,6 @@ module Shared
run_cmd "git merge #{branch}"
end
def git_branch (branch)
run_cmd "git branch #{branch}"
end
def git_push (branch)
run_cmd "git push origin #{branch}"
end

View File

@@ -1,117 +0,0 @@
require 'ostruct'
require 'optparse'
module Xfind
class Commander
attr_accessor :options
def initialize (argv)
@options = OpenStruct.new
options.debug = false
options.names = []
options.paths = [
{exclude: true, pattern: '.git'},
{exclude: true, pattern: 'node_modules'}
]
@option_parser = OptionParser.new do |op|
op.banner = "Usage: xfind options term(s)"
op.on('-d','--[no-]debug') do |argument|
options.debug = argument
end
op.on('-n NAME', 'include NAME') do |argument|
options.names << {exclude: false, pattern: argument}
end
op.on('-N NAME','exclude NAME') do |argument|
options.names << {exclude: true, pattern: argument}
end
op.on('-p PATH','include PATH') do |argument|
options.paths << {exclude: false, pattern: argument}
end
op.on('-P PATH','exclude PATH') do |argument|
options.paths << {exclude: true, pattern: argument}
end
op.on_tail('-h','--help') do |argument|
puts op
exit
end
end
@option_parser.parse!(argv)
options.terms = argv # must be after parse!
end
def valid?
true #options.terms.size > 0
end
def help
puts @option_parser
exit
end
def execute
include_paths = options.paths.reject {|x| x[:exclude] }.map {|x| "-path '*/#{x[:pattern]}/*'"}
if include_paths.size > 1
include_paths = include_paths.join(' -o ')
include_paths = ['\(', include_paths, '\)']
end
include_paths = include_paths.join(' ')
exclude_paths = options.paths.select {|x| x[:exclude] }.map {|x| "! -path '*/#{x[:pattern]}/*'"}
if exclude_paths.size > 1
exclude_paths = exclude_paths.join(' -a ')
exclude_paths = ['\(', exclude_paths, '\)']
end
exclude_paths = exclude_paths.join(' ')
include_names = options.names.reject {|x| x[:exclude] }.map {|x| "-name '*.#{x[:pattern]}'"}
if include_names.size > 1
include_names = include_names.join(' -o ')
include_names = ['\(', include_names, '\)']
end
include_names = include_names.join(' ')
exclude_names = options.names.select {|x| x[:exclude] }.map {|x| "! -name '*.#{x[:pattern]}'"}
if exclude_names.size > 1
exclude_names = exclude_names.join(' -a ')
exclude_names = ['\(', exclude_names, '\)']
end
exclude_names = exclude_names.join(' ')
commands = [
["find", ".", "-type f", include_names, exclude_names, include_paths, exclude_paths].join(" "),
"sort",
]
if options.terms.size > 0
terms = options.terms.map {|x| "grep --color=auto #{x}"}.join(' | ')
commands << ["xargs", terms].join(' ')
end
command = commands.join('|')
if options.debug
puts command
else
system command
end
end
private
def default_environment
Xfind::SimpleEnv.new
end
end
end

18
package-lock.json generated
View File

@@ -1,18 +0,0 @@
{
"name": "git-utilities",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"commander": {
"version": "2.20.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz",
"integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ=="
},
"lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
}
}
}

View File

@@ -1,27 +0,0 @@
{
"name": "git-utilities",
"version": "1.0.0",
"description": "This is a collection of simple command-line scripts, bash aliases, and bash utilities that make using `git` even easier.",
"main": "index.js",
"directories": {
"lib": "lib"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/rkiel/git-utilities.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/rkiel/git-utilities/issues"
},
"homepage": "https://github.com/rkiel/git-utilities#readme",
"dependencies": {
"commander": "^2.20.0",
"lodash": "^4.17.21"
}
}