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

Support MacOS #24

Merged
merged 8 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ This is a simple shell script that can be used to ignore files from dropbox usin

### Basic Installation

dropboxignore is installed by running one of the following commands in your terminal. You can install this via the command-line with either curl, wget or another similar tool. `attr` and `git` package should be installed on your system.
dropboxignore is installed by running one of the following commands in your terminal. You can install this via the command-line with either curl, wget or another similar tool. `attr` and `git` should be installed on your system, as well as Homebrew if you are on macOS.

| Mathod | Command |
|--------|---------------------------------------------------------------------------------------------------------------|
| curl | `sudo sh -c "$(curl -fsSL https://raw.githubusercontent.com/sp1thas/dropboxignore/master/utils/install.sh)"` |
| wget | `sudo sh -c "$(wget -qO- https://raw.githubusercontent.com/sp1thas/dropboxignore/master/utils/install.sh)"` |
| fetch | `sudo sh -c "$(fetch -o - https://raw.githubusercontent.com/sp1thas/dropboxignore/master/utils/install.sh)"` |


### Snap Installation

[![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-white.svg)](https://snapcraft.io/dropboxignore)
Expand Down
10 changes: 6 additions & 4 deletions bin/dropboxignore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ TOTAL_N_REVERTED_FILES=0
TOTAL_N_GENERATED_FILES=0
BASE_FOLDER="$PWD"
FILE_ATTR_NAME="com.dropbox.ignored"
[[ $MACHINE == Darwin ]] && GREP_CMD="ggrep" || GREP_CMD="grep"
[[ $MACHINE == Darwin ]] && DIFF_CMD="$(brew --prefix)/bin/diff" || DIFF_CMD="diff"

DEFAULT="\e[0m"
GREEN="\e[32m"
Expand Down Expand Up @@ -290,7 +292,7 @@ EOF
# Update status.
#######################################
update_dropboxignore_file() {
diff_content=$(diff --new-line-format="" --unchanged-line-format="" --ignore-blank-lines --ignore-tab-expansion --ignore-space-change --ignore-trailing-space -I "# [Automatically|-]" "${1}" "${2}")
diff_content=$("$DIFF_CMD" --new-line-format="" --unchanged-line-format="" --ignore-blank-lines --ignore-tab-expansion --ignore-space-change --ignore-trailing-space -I "# [Automatically|-]" "${1}" "${2}")
if [ -n "$diff_content" ]; then
tee -a "$2" >/dev/null <<EOF
# Automatically updated .dropboxignore file at "$(date)"
Expand Down Expand Up @@ -333,7 +335,7 @@ update_dropboxignore_files() {
generate_dropboxignore_files() {
find_gitignore_files "$1"
for gitignore_file in $GITIGNORE_FILES; do
if grep -q -P '^\s*!' "$gitignore_file"; then
if "$GREP_CMD" -q -P '^\s*!' "$gitignore_file"; then
echo -e "$YELLOW$(get_relative_path "$gitignore_file" "$BASE_FOLDER") contains exception patterns, will be ignored"
continue
fi
Expand Down Expand Up @@ -424,7 +426,7 @@ ignore_files() {
for dropboxignore_file in $DROPBOX_IGNORE_FILES; do
file_total_results=0
# shellcheck disable=SC2013
if grep -q -P '^\s*!' "$dropboxignore_file"; then
if "$GREP_CMD" -q -P '^\s*!' "$dropboxignore_file"; then
echo -e "$YELLOW$(get_relative_path "$dropboxignore_file" "$BASE_FOLDER") contains exception patterns, will be ignored"
continue
fi
Expand All @@ -438,7 +440,7 @@ ignore_files() {
((n_results++))
done < <(find "$(dirname "$dropboxignore_file")/$subdir" -name "$pattern")
file_total_results=$((file_total_results + n_results))
done < <(grep -v -P '^\s*$|^\s*\#|^\s*!' "$dropboxignore_file")
done < <("$GREP_CMD" -v -P '^\s*$|^\s*\#|^\s*!' "$dropboxignore_file")
log_debug "Matched files because of '$(get_relative_path "$dropboxignore_file" "$BASE_FOLDER")': $file_total_results"
done
fi
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Installation

Below you will all the available installation options. dropboxignore is currently available only for Mac OS and Linux systems.
Below you will all the available installation options. dropboxignore is currently available only for macOS and Linux systems. For macOS, Homebrew is required.

## Basic Installation

Expand Down
9 changes: 9 additions & 0 deletions utils/install.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
#!/usr/bin/env bash

# First install additional dependencies if on macOS
MACHINE="$(uname -s)"
if [ "$MACHINE" == Darwin ]; then
sudo -u "$SUDO_USER" HOMEBREW_NO_AUTO_UPDATE=1 brew install diffutils
sudo -u "$SUDO_USER" HOMEBREW_NO_AUTO_UPDATE=1 brew install grep
fi

# Install dropboxignore command
rm -rf /usr/local/bin/dropboxignore
git clone https://github.com/sp1thas/dropboxignore.git
make -C dropboxignore install
Expand Down