Skip to content

Commit

Permalink
build: v0.2.4
Browse files Browse the repository at this point in the history
* refactor: prepare v0.2.4
* feat: optional destination & delete mode for git
* refactor: update gitsrc sample
* fix: don't use 0000
* style: trim newline
  • Loading branch information
sh0shin authored Mar 19, 2021
1 parent e9f5b66 commit c4591d5
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ install -m 0555 dothier/dothier /usr/local/bin

## Usage
```
dothier v0.2.2 ( https://sh0shin.org/dothier )
dothier v0.2.4 ( https://sh0shin.org/dothier )
Usage: dothier [-CRghnrstv] [-f file] [-d dir] [-H home] [-k file]
Options:
-C : Disable colorized output
Expand Down
89 changes: 74 additions & 15 deletions dothier
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ set -o pipefail -eu

# self, version, url
readonly dothier_self="${0##*/}"
readonly dothier_version="v0.2.3"
readonly dothier_version="v0.2.4"
readonly dothier_url="https://sh0shin.org/dothier"

## dothier config
Expand All @@ -45,7 +45,6 @@ readonly dothier_url="https://sh0shin.org/dothier"
: "${dothier_home:="$HOME"}"
# -R
: "${dothier_remove:=false}"

# -c
: "${dothier_config:="$HOME/.config/dothier"}"
# -d
Expand Down Expand Up @@ -587,21 +586,53 @@ dothier_git() {
gitdst_path="$(dirname "$home/$path")"
fi

# inherit path
if [[ -n "$gitdst" ]]
# check & set gitdst gitmode gitpull gitdepth
if [[ $gitdst =~ ^(@)?[0-9]{4}$ ]]
then
gitdst="$gitdst_path/$gitdst"
# mode
gitmode=$gitdst
gitdst=
fi

if [[ -n "$gitmode" ]]
if [[ $gitmode =~ ^(yes|no)$ ]]
then
if [[ "$gitmode" =~ ^@ ]]
then
gitmode="${gitmode##@}"
tmex=true
else
tmex=false
fi
# pull
gitpull=$gitmode
gitmode=
fi

if [[ $gitdst =~ ^(yes|no)$ ]]
then
# pull
gitpull=$gitdst
gitdst=
fi

if [[ $gitdst =~ ^[0-9]$ ]]
then
# depth
gitdepth=$gitdst
gitdst=
fi

if [[ $gitmode =~ ^[0-9]$ ]]
then
# depth
gitdepth=$gitmode
gitmode=
fi

if [[ $gitpull =~ ^[0-9]$ ]]
then
# depth
gitdepth=$gitpull
gitpull=
fi

if [[ -n "$gitdst" ]]
then
# path
gitdst="$gitdst_path/$gitdst"
fi

# defaults
Expand All @@ -610,6 +641,31 @@ dothier_git() {
: "${gitpull:="yes"}"
: "${gitdepth:="1"}"

# tmutil exclude
if [[ "$gitmode" =~ ^@ ]]
then
gitmode="${gitmode##@}"
tmex=true
else
tmex=false
fi

# delete mode
if [[ "$gitmode" == 0000 ]]
then
if [[ -d "$gitdst" ]]
then
if [[ $dothier_remove == true ]]
then
dothier_msg w "removing git: $gitdst"
$dothier_runner rm -r "$gitdst"
else
dothier_msg w "NOT removing git: $gitdst"
fi
fi
return
fi

if [[ -d "$gitdst/.git" ]]
then
if [[ "$gitpull" == "yes" ]] && [[ $dothier_gitpull == true ]]
Expand All @@ -625,7 +681,10 @@ dothier_git() {
fi

# mode
dothier_mode "$gitdst" "$type" "$gitmode"
if [[ -d "$gitdst" ]]
then
dothier_mode "$gitdst" "$type" "$gitmode"
fi

# tmutil
dothier_tmutil "$gitdst" "$tmex"
Expand Down Expand Up @@ -747,7 +806,7 @@ dothier_read() {
# link
elif [[ "$type" =~ link ]]
then
_mode="0000" # currently unused
_mode="0777" # currently unused
fi

# match
Expand Down
7 changes: 4 additions & 3 deletions gitsrc.sample
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#! <git-repository-url> [destination] [[@]mode] [pull] [depth]

# TODO: optional mode if pull and/or depth is used

# clone the repository as name dothier
# mode is set from umask, pull defaults to yes, depth to 1
https://github.com/sh0shin/dothier.git

# clone the repository as name dothier with mode set
https://github.com/sh0shin/dothier.git 0700

# clone the repository as name dothier-git-src (mode: 0750)
# macos users can use @0750 to exclude from time machine backups
https://github.com/sh0shin/dothier.git dothier-git-src 0750
https://github.com/sh0shin/dothier.git dothier-git-src @0750

0 comments on commit c4591d5

Please sign in to comment.