File tree 6 files changed +106
-1
lines changed
6 files changed +106
-1
lines changed Original file line number Diff line number Diff line change 3
3
4
4
Small Shell Tools
5
5
6
+
7
+ Install
8
+ -------
9
+
10
+ ### Installation
11
+
12
+ Utils must be installed in ~ /utils.
13
+
14
+ To install, run ` git clone https://github.com/adriendupuis/utils.git -b master ~/utils && ${0//[^a-z]/} ~/utils/install.sh $0; `
15
+
16
+ ### Maintenance
17
+
18
+ - ` utils-update ` : Update utils to last master release
19
+ - ` utils-install <version> ` : Install a given version of Utils, the version can be a tag, a branch or a commit
20
+ - ` utils-version ` : Get actual Utils version
21
+
22
+
6
23
TODO
7
24
----
8
25
9
- * Portage (originally done with macOs Catalina, ensure that it works on other unixoids)
26
+ * Portage (originally done with macOs Catalina, ensure that it works on other unixoids)
27
+ * Unit tests
Original file line number Diff line number Diff line change
1
+ source ~ /utils/functions.sh;
2
+
3
+ alias utils-install=' utils-update' ;
4
+ alias utils-update=' _utils_update' ;
5
+ alias utils-version=' _utils_version'
6
+
1
7
alias git-graph=' git log --all --graph --date-order --oneline --decorate' ;
2
8
alias git-current-branch=' git rev-parse --abbrev-ref HEAD' ;
3
9
alias git-current-commit=' git rev-parse --verify --short HEAD' ;
Original file line number Diff line number Diff line change
1
+ function _utils_update {
2
+ cd ~ /utils;
3
+
4
+ previous=$( _utils_version) ;
5
+
6
+ git fetch --quiet;
7
+ if [[ 0 -lt $# ]]; then
8
+ git checkout --quiet " $1 " 2> /dev/null;
9
+ if [[ 0 -lt $? ]]; then
10
+ echo " Error: can't checkout $1 " ;
11
+ return ;
12
+ fi ;
13
+ else
14
+ git checkout --quiet master 2> /dev/null;
15
+ fi ;
16
+ git pull --quiet;
17
+
18
+ current=$( _utils_version) ;
19
+
20
+ if [ " $current " == " $previous " ]; then
21
+ echo " Info: Utils is up-to-date and in $previous " ;
22
+ else
23
+ rc=~ /.${SHELL##*/ } rc;
24
+ if [[ -f $rc ]]; then
25
+ source $rc ;
26
+ echo " Info: $rc reloaded." ;
27
+ else
28
+ source ~ /utils/aliases.sh;
29
+ echo ' Notice: ~/utils/aliases.sh reloaded. Shell RC file might need a manual reload too.' ;
30
+ fi ;
31
+ echo " Info: Utils updated from $previous to $current ." ;
32
+ fi
33
+ }
34
+
35
+ function _utils_version {
36
+ cd ~ /utils;
37
+
38
+ git fetch --tags --quiet;
39
+ version=$( git describe --tags 2> /dev/null) ;
40
+ if [ -z " $version " ]; then
41
+ version=$( git rev-parse --verify --short HEAD) ;
42
+ fi ;
43
+
44
+ echo " $version " ;
45
+ }
Original file line number Diff line number Diff line change
1
+ # First installation script (just after having cloned the repository)
2
+
3
+ if [[ " ${1// [^a-z]/ } " =~ ' zsh' ]]; then
4
+ rc=' zshrc' ;
5
+ elif [[ " $1 " =~ ' bash' ]]; then
6
+ rc=' bashrc' ;
7
+ else
8
+ echo " Error: Unsupported shell." ;
9
+ exit 1;
10
+ fi ;
11
+
12
+ source ~ /utils/text.sh;
13
+ ERROR=" ${TXT_FG_WHITE}${TXT_BG_RED} " ;
14
+ WARNING=" ${TXT_FG_BLACK}${TXT_BG_YELLOW} " ;
15
+ COMMENT=" ${TXT_FG_BLUE} " ;
16
+ RESET=$TXT_RESET ;
17
+
18
+ if [[ -f ~ /utils/rc/$rc ]]; then
19
+ if [[ -z ` grep " /utils/rc/$rc " ~ /.$rc ; ` ]]; then
20
+ echo -e " Status: Load ~/utils/rc/$rc into ~/.$rc …" ;
21
+
22
+ echo ' ' >> ~ /.$rc ;
23
+ echo ' # https://github.com/adriendupuis/utils' >> ~ /.$rc ;
24
+ echo " source \$ HOME/utils/rc/$rc " >> ~ /.$rc ;
25
+
26
+ echo " ${COMMENT} Notice: Utils will be automatically available in next terminals. If Utils is needed in the current one, the following command can be run:" ;
27
+ echo " source ~/.$rc ;${RESET} " ;
28
+ else
29
+ echo " Info: ~/utils/rc/$rc already loaded from ~/.$rc ." ;
30
+ fi ;
31
+ else
32
+ echo " Info: No “rc” file available for this shell."
33
+ fi ;
Original file line number Diff line number Diff line change
1
+ source $HOME /utils/aliases.sh;
Original file line number Diff line number Diff line change
1
+ setopt interactivecomments; # Allow to have a comment in a command line; Avoid error like "zsh: command not found: #"
2
+ source $HOME /utils/aliases.sh;
You can’t perform that action at this time.
0 commit comments