Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] First Release #1

Draft
wants to merge 56 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
38129bf
text.sh: Text formatting helper
adriendupuis Mar 31, 2020
0daa70d
aliases.sh: Start a list of useful aliases
adriendupuis Mar 31, 2020
dfb235a
aliases.sh: Fix git options/arguments
adriendupuis Apr 16, 2020
a8f34aa
aliases.sh: Add really hard git reset
adriendupuis Apr 16, 2020
54ff146
aliases.sh + git-current-tag
adriendupuis Apr 27, 2020
cd4dcc5
aliases.sh: git-current-tag: Force update from remote
adriendupuis Apr 28, 2020
9e3b178
aliases.sh: Implement git-clean-local-branches
adriendupuis May 12, 2020
40fbb33
aliases.sh: Quiet git-current-tag
adriendupuis May 12, 2020
52e8650
aliases.sh: Add self maintenance aliases
adriendupuis May 12, 2020
04179bd
(minor) Format aliases.sh
adriendupuis May 12, 2020
4232801
Merge branch 'develop' into feature/self
adriendupuis May 13, 2020
8b9c331
Move function to another file
adriendupuis May 13, 2020
10795ba
aliases.sh: Rewrite to make `git-clean-local-branches --force` possible
adriendupuis May 15, 2020
fd062dc
Continue utils-update
adriendupuis May 15, 2020
6136801
Continue utils-update
adriendupuis May 15, 2020
272cca0
Continue utils-update: Error handling
adriendupuis May 15, 2020
75f7d2b
Continue README.md
adriendupuis May 15, 2020
b0d8e48
Replace \e w/ \x1B for bash compatibility
adriendupuis May 15, 2020
719efdf
Merge pull request #3 from adriendupuis/fix/text
adriendupuis May 20, 2020
9944c41
Add a standard gitignore
adriendupuis May 29, 2020
f1ed28b
Update README.md
adriendupuis May 29, 2020
d2476f3
git-global-ignore: Ask before overwrite
adriendupuis Jun 1, 2020
3136561
git-global-ignore: Set target
adriendupuis Jun 1, 2020
7ff978d
Installation script
adriendupuis Jun 4, 2020
e8ae02c
Format rc/*rc files
adriendupuis Jun 4, 2020
9d69b9d
Format install.sh output
adriendupuis Jun 4, 2020
6158494
install.sh: If shell not supported, text formatting shouldn't be used.
adriendupuis Jun 4, 2020
201ebe6
install.sh: Fix “zsh: command not found: -zsh”
adriendupuis Jun 10, 2020
9dd73bc
install.sh: Fix rc path in a notice
adriendupuis Jun 10, 2020
7e34c75
utils-install: Enh. current terminal update
adriendupuis Jun 10, 2020
278282c
utils-install: Enh. output
adriendupuis Jun 10, 2020
b0faea9
utils-install: Fix $SHELL usage; Enh. output
adriendupuis Jun 10, 2020
76d1fc4
utils-install: Factorize
adriendupuis Jun 10, 2020
b6ab5b4
utils-install: Fix rc file path
adriendupuis Jun 10, 2020
214056b
Merge branch 'develop' into feature/self
adriendupuis Jun 10, 2020
e8b3317
Merge pull request #2 from adriendupuis/feature/self
adriendupuis Jun 10, 2020
92ea833
(minor) Add uninstall to TODO list
adriendupuis Jun 10, 2020
23ec10e
Add `sf-cs-fixer` alias (PHP CS Fixer w/ Symfony rules)
adriendupuis Jul 8, 2020
ae4a22c
sf-cs-fixer → sf-cs-fix
adriendupuis Sep 9, 2020
a399211
aliases.sh: Add `gz` to keep original file when using `gzip` (aka `gu…
adriendupuis Nov 9, 2020
9bc11cc
install.sh: Fix "sh: command not found: binzsh"
adriendupuis Nov 18, 2020
ee78181
aliases.sh: Add `git-force-pull`
adriendupuis Nov 18, 2020
bd9384b
git-clean-local-branches + --prune
adriendupuis Dec 17, 2020
1a0bbc4
Update for PHP-CS-Fixer v3
adriendupuis May 27, 2021
46450f2
gitignore as used file, not simply a template
adriendupuis Nov 5, 2021
ded9bbf
Merge remote-tracking branch 'origin/develop' into feature/gitignore
adriendupuis Nov 5, 2021
d4d2911
Merge pull request #7 from adriendupuis/feature/gitignore
adriendupuis Nov 5, 2021
bb1f31f
install.sh: Fix $0 === -zsh bug
adriendupuis Nov 5, 2021
4d01500
install.sh: Fix var usage (`$rc…` doesn't exist)
adriendupuis Nov 5, 2021
a9abd0f
(minor) aliases.sh: Add missing trailing semi-colon
adriendupuis Nov 5, 2021
deb5c27
aliases.sh: Add git-tag-list
adriendupuis Mar 29, 2022
e86b10b
functions.sh: Add `git-delete-tag`
adriendupuis Apr 6, 2022
bcff692
aliases.sh: Add commit hash's 8 first chars to git-tag-list
adriendupuis Apr 29, 2022
c01da76
functions.sh: avoid _utils_version changing current directory
adriendupuis Aug 3, 2023
68e07cd
install.sh: Fix color usage
adriendupuis Aug 3, 2023
90a8857
utils-update: Reload if there is local changes
adriendupuis Aug 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
Utils
=====

Small tools
Small Shell Tools


Install
-------

### Installation

Utils must be installed in ~/utils.

To install, run `git clone https://github.com/adriendupuis/utils.git -b master ~/utils && ~/utils/install.sh ${0##-};`

### Maintenance

- `utils-update`: Update utils to last master release
- `utils-install <version>`: Install a given version of Utils, the version can be a tag, a branch or a commit
- `utils-version`: Get actual Utils version


TODO
----

* Uninstall doc and tool
* Portage (originally done with macOs Catalina, ensure that it works on other unixoids)
* Unit tests
20 changes: 20 additions & 0 deletions aliases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
source ~/utils/functions.sh;

alias utils-install='utils-update';
alias utils-update='_utils_update';
alias utils-version='_utils_version';

alias git-graph='git log --all --graph --date-order --oneline --decorate';
alias git-current-branch='git rev-parse --abbrev-ref HEAD';
alias git-current-commit='git rev-parse --verify --short HEAD';
alias git-current-tag='git fetch --tags --force --quiet && git describe --tags 2> /dev/null';
alias git-tag-list='git fetch --tags --force --quiet && git tag --sort=-committerdate --format "%(refname:short)%09%(committerdate:short)%09%(objectname:short=8)"';
alias git-reset='git reset --hard origin/$(git-current-branch)';
alias git-clean-local-branches='git fetch --prune --quiet && git branch -vv | grep -v "^\*" | grep "\[.*: gone\]" | cut -d " " -f 3 | xargs git branch --delete';
alias git-force-pull='git fetch --force && git pull --force';
alias git-delete-tag='_git_delete_tag';
alias git-global-ignore='git config --global core.excludesfile "~/utils/gitignore"';

alias sf-cs-fix='php-cs-fixer fix --rules=@Symfony';

alias gz='gzip --keep';
54 changes: 54 additions & 0 deletions functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function _utils_update {
cd ~/utils;

target=${1:-master};
previous=$(_utils_version);

git fetch --quiet;
git checkout --quiet "$target" 2> /dev/null;
if [[ 0 -lt $? ]]; then
echo "Error: can't checkout $target";
return;
fi;
git pull --quiet;

current=$(_utils_version);

if [[ "$current" == "$previous" ]] && [[ '' == "$(git status | grep 'modified:')" ]]; then
echo "Info: Utils is up-to-date and at $current";
else
rc=~/.${SHELL##*/}rc;
if [[ -f $rc ]]; then
source $rc;
echo "Info: $rc reloaded.";
else
source ~/utils/aliases.sh;
echo 'Notice: ~/utils/aliases.sh reloaded. Shell RC file might need a manual reload too.';
fi;
echo "Info: Utils updated from $previous to $current.";
fi
}

function _utils_version {
cd ~/utils;

git fetch --tags --quiet;
version=$(git describe --tags 2> /dev/null);
if [ -z "$version" ]; then
version=$(git rev-parse --verify --short HEAD);
fi;

echo "$version";

cd - > /dev/null;
}

function _git_delete_tag {
if [[ 1 -eq $# ]]; then
git tag -d $1;
git push --delete origin $1;
elif [[ 2 -eq $# ]]; then
git tag -d $2;
git push --delete $1 $2;
fi;
}
5 changes: 5 additions & 0 deletions gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Global core.excludesfile
.idea/
.php_cs.cache
.php-cs-fixer.cache
.DS_Store
33 changes: 33 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# First installation script (just after having cloned the repository)

if [[ `basename $1` = 'zsh' ]]; then
rc='zshrc';
elif [[ `basename $1` = 'bash' ]]; then
rc='bashrc';
else
echo "Error: Unsupported shell.";
exit 1;
fi;

source ~/utils/text.sh;
ERROR="${TXT_FG_WHITE}${TXT_BG_RED}";
WARNING="${TXT_FG_BLACK}${TXT_BG_YELLOW}";
COMMENT="${TXT_FG_BLUE}";
RESET=$TXT_RESET;

if [[ -f ~/utils/rc/$rc ]]; then
if [[ -z `grep "/utils/rc/$rc" ~/.$rc;` ]]; then
echo "Status: Load ~/utils/rc/${rc} into ~/.${rc}…";

echo '' >> ~/.$rc;
echo '# https://github.com/adriendupuis/utils' >> ~/.$rc;
echo "source \$HOME/utils/rc/$rc" >> ~/.$rc;

echo -e "${COMMENT}Notice: Utils will be automatically available in next terminals. If Utils is needed in the current one, the following command can be run:";
echo -e "source ~/.$rc;${RESET}";
else
echo "Info: ~/utils/rc/$rc already loaded from ~/.$rc.";
fi;
else
echo -e "${WARNING}Warning: No “rc” file available for this shell.${RESET}"
fi;
1 change: 1 addition & 0 deletions rc/bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source $HOME/utils/aliases.sh;
2 changes: 2 additions & 0 deletions rc/zshrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
setopt interactivecomments; # Allow to have a comment in a command line; Avoid error like "zsh: command not found: #"
source $HOME/utils/aliases.sh;
14 changes: 14 additions & 0 deletions text-test.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

source text.sh;

echo -e "${TXT_BLINK}${TXT_UNDERLINE}${TXT_FG_GREEN}gr${TXT_REVERSE}e${TXT_REVERSE_RESET}en${TXT_RESET}!";

ERROR="${TXT_FG_WHITE}${TXT_BG_RED}";
WARNING="${TXT_FG_BLACK}${TXT_BG_YELLOW}";
COMMENT="${TXT_FG_BLUE}";
RESET=$TXT_RESET;

echo -e "${ERROR}Error${RESET}"
echo -e "${WARNING}Warning${RESET}"
echo -e "${COMMENT}Comment${RESET}"
14 changes: 14 additions & 0 deletions text-test.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env zsh

source text.sh;

echo -e "${TXT_BLINK}${TXT_UNDERLINE}${TXT_FG_GREEN}gr${TXT_REVERSE}e${TXT_REVERSE_RESET}en${TXT_RESET}!";

ERROR="${TXT_FG_WHITE}${TXT_BG_RED}";
WARNING="${TXT_FG_BLACK}${TXT_BG_YELLOW}";
COMMENT="${TXT_FG_BLUE}";
RESET=$TXT_RESET;

echo -e "${ERROR}Error${RESET}"
echo -e "${WARNING}Warning${RESET}"
echo -e "${COMMENT}Comment${RESET}"
56 changes: 56 additions & 0 deletions text.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

# Cancel Format and Color
TXT_RESET='\x1B[0m';

# Text Format
TXT_BOLD='\x1B[1m';
TXT_BOLD_RESET='\x1B[21m';
TXT_DIM='\x1B[2m';
TXT_DIM_RESET='\x1B[22m';
TXT_UNDERLINE='\x1B[4m';
TXT_UNDERLINE_RESET='\x1B[24m';
TXT_BLINK='\x1B[5m';
TXT_BLINK_RESET='\x1B[25m';
TXT_REVERSE='\x1B[7m';
TXT_REVERSE_RESET='\x1B[27m';
TXT_HIDDEN='\x1B[8m';
TXT_HIDDEN_RESET='\x1B[28m';

# Text Color
## Default
TXT_FG_DEFAULT='\x1B[39m';
TXT_BG_DEFAULT='\x1B[49m';
## Gray Levels
TXT_FG_BLACK='\x1B[30m';
TXT_BG_BLACK='\x1B[40m';
TXT_FG_DARK_GRAY='\x1B[90m';
TXT_BG_DARK_GRAY='\x1B[100m';
TXT_FG_LIGHT_GRAY='\x1B[37m';
TXT_BG_LIGHT_GRAY='\x1B[47m';
TXT_FG_WHITE='\x1B[97m';
TXT_BG_WHITE='\x1B[107m';
## Colors
TXT_FG_RED='\x1B[31m';
TXT_BG_RED='\x1B[41m';
TXT_FG_LIGHT_RED='\x1B[91m';
TXT_BG_LIGHT_RED='\x1B[101m';
TXT_FG_GREEN='\x1B[32m';
TXT_BG_GREEN='\x1B[42m';
TXT_FG_LIGHT_GREEN='\x1B[92m';
TXT_BG_LIGHT_GREEN='\x1B[102m';
TXT_FG_YELLOW='\x1B[33m';
TXT_BG_YELLOW='\x1B[43m';
TXT_FG_LIGHT_YELLOW='\x1B[93m';
TXT_BG_LIGHT_YELLOW='\x1B[103m';
TXT_FG_BLUE='\x1B[34m';
TXT_BG_BLUE='\x1B[44m';
TXT_FG_LIGHT_BLUE='\x1B[94m';
TXT_BG_LIGHT_BLUE='\x1B[104m';
TXT_FG_MAGENTA='\x1B[35m';
TXT_BG_MAGENTA='\x1B[45m';
TXT_FG_LIGHT_MAGENTA='\x1B[95m';
TXT_BG_LIGHT_MAGENTA='\x1B[105m';
TXT_FG_CYAN='\x1B[36m';
TXT_BG_CYAN='\x1B[46m';
TXT_FG_LIGHT_CYAN='\x1B[96m';
TXT_BG_LIGHT_CYAN='\x1B[106m';