This file contains hidden or 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
| #!/bin/bash | |
| set -o errexit # Exit on error | |
| set -o nounset # Treat unset variables as an error | |
| set -o pipefail # Consider errors in a pipeline | |
| default_editor=${EDITOR:-vim} | |
| temp_file_path=$(mktemp /tmp/clip_temp.XXXXXX) | |
| trap "rm -f $temp_file_path" EXIT | |
| pbpaste > $temp_file_path | |
| file_md5_hash=$(md5 $temp_file_path) | |
| $default_editor $temp_file_path | |
| new_file_md5_hash=$(md5 $temp_file_path) | |
| if [ "$file_md5_hash" != "$new_file_md5_hash" ]; then | |
| echo "File has been modified. Updating clipboard with editor contents" | |
| pbcopy < $temp_file_path | |
| else | |
| echo "No changes detected, ignoring output" | |
| fi |