Skip to content

Commit e8b3317

Browse files
authored
Merge pull request #2 from adriendupuis/feature/self
Self Installation & Maintenance
2 parents f1ed28b + 214056b commit e8b3317

File tree

6 files changed

+106
-1
lines changed

6 files changed

+106
-1
lines changed

README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,25 @@ Utils
33

44
Small Shell Tools
55

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+
623
TODO
724
----
825

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

aliases.sh

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
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+
17
alias git-graph='git log --all --graph --date-order --oneline --decorate';
28
alias git-current-branch='git rev-parse --abbrev-ref HEAD';
39
alias git-current-commit='git rev-parse --verify --short HEAD';

functions.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
}

install.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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;

rc/bashrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source $HOME/utils/aliases.sh;

rc/zshrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
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;

0 commit comments

Comments
 (0)