-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(grimshot): modularize and clean up with functional helpers
- Introduced functional helper methods: `when`, `if_else`, and `any` for cleaner, more maintainable logic. - Refactored conditional handling in `notifyOk`, `notifyError`, and `check` functions to leverage the new helper methods. - Moved usage message printing to a dedicated `printUsageMsg` function. - Extracted subject-specific logic (e.g., area, window, screen) into standalone functions: `selectArea`, `selectWindow`, etc. - Improved error handling by introducing functions like `handleScreenshotSuccess`, `handleScreenshotFailure`, and `handleSaveCopy`. - Reformatted code and improved readability by using consistent formatting for case statements and conditions. This refactor enhances code maintainability by isolating logic into reusable components, improving clarity and simplifying future changes.
- Loading branch information
Showing
2 changed files
with
173 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#! /bin/sh | ||
when() { | ||
condition=$1 | ||
action=$2 | ||
|
||
if eval "$condition"; then | ||
eval "$action" | ||
fi | ||
} | ||
|
||
whenOtherwise() { | ||
condition=$1 | ||
true_action=$2 | ||
false_action=$3 | ||
|
||
if eval "$condition"; then | ||
eval "$true_action" | ||
else | ||
eval "$false_action" | ||
fi | ||
} | ||
|
||
any() { | ||
for tuple in "$@"; do | ||
condition=$(echo "$tuple" | cut -d: -f1) | ||
action=$(echo "$tuple" | cut -d: -f2-) | ||
if eval "$condition"; then | ||
eval "$action" | ||
return 0 | ||
fi | ||
done | ||
return 1 # No conditions matched | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters