Skip to content

Commit

Permalink
Merge pull request #9 from sargsyan/eliminate-globbing-and-splitting-…
Browse files Browse the repository at this point in the history
…issues

eliminate globbing and splitting from libraries used for notifications service
  • Loading branch information
sargsyan authored Sep 22, 2018
2 parents 5fd416a + bf657ed commit 28f2577
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
16 changes: 8 additions & 8 deletions lib/last_shown_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ readonly LATEST_SHOWN_FILE="$HOME/.latest_shown"
function get_last_shown_commit_date() {
local config_name=$1

if [ -f $LATEST_SHOWN_FILE ]; then
echo $(cat $LATEST_SHOWN_FILE | grep -w "$config_name" | cut -d' ' -f2)
if [ -f "$LATEST_SHOWN_FILE" ]; then
echo $(cat "$LATEST_SHOWN_FILE" | grep -w "$config_name" | cut -d' ' -f2)
else
echo "0"
fi
Expand All @@ -15,15 +15,15 @@ function get_last_shown_commit_date() {
function save_last_shown_commit_date() {
local config_name=$1
local value=$2
if [ -f $LATEST_SHOWN_FILE ]; then
local line_number=$(grep -wn "$config_name" $LATEST_SHOWN_FILE | cut -d: -f1)
if [ -f "$LATEST_SHOWN_FILE" ]; then
local line_number=$(grep -wn "$config_name" "$LATEST_SHOWN_FILE" | cut -d: -f1)
if [[ -n "$line_number" ]]; then
sed -i .bak "${line_number}s|.*|$config_name $value|" $LATEST_SHOWN_FILE &&
rm $LATEST_SHOWN_FILE.bak
sed -i .bak "${line_number}s|.*|$config_name $value|" "$LATEST_SHOWN_FILE" &&
rm "$LATEST_SHOWN_FILE.bak"
else
echo $config_name $value >> $LATEST_SHOWN_FILE
echo "$config_name" "$value" >> "$LATEST_SHOWN_FILE"
fi
else
echo $config_name $value >> $LATEST_SHOWN_FILE
echo "$config_name" "$value" >> "$LATEST_SHOWN_FILE"
fi
}
14 changes: 7 additions & 7 deletions lib/notifier.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#!/bin/bash

readonly LIB_DIR_NAME=$(dirname $BASH_SOURCE)
readonly LIB_DIR_NAME=$(dirname "$BASH_SOURCE")
readonly EMOJIFY=$([ -x "$(command -v emojify)" ] && echo emojify || echo cat)
TERMINAL_NOTIFIER=$LIB_DIR_NAME/../github-notifier.app/Contents/MacOS/terminal-notifier

function show_notification_window() {
local title=$(echo $1 | $EMOJIFY)
local subtitle=$(echo $2 | $EMOJIFY)
local message=$(echo $3 | $EMOJIFY)
local title=$(echo "$1" | $EMOJIFY)
local subtitle=$(echo "$2" | $EMOJIFY)
local message=$(echo "$3" | $EMOJIFY)
local link=$4
local icon=$5

#remove '[' and '<' characters from begining of the strings
#because of https://github.com/julienXX/terminal-notifier/issues/134
local title=$(echo $title | sed 's|^\[\(.*\)\]|\1|' | sed -E 's|^[\[\<]+||')
local message=$(echo $message | sed 's|^\[\(.*\)\]|\1|' | sed -E 's|^[\[\<]+||')
local title=$(echo "$title" | sed 's|^\[\(.*\)\]|\1|' | sed -E 's|^[\[\<]+||')
local message=$(echo "$message" | sed 's|^\[\(.*\)\]|\1|' | sed -E 's|^[\[\<]+||')

$TERMINAL_NOTIFIER --group 1 -title "$title" -subtitle "$subtitle" -message "$message" -open $link -appIcon $icon
$TERMINAL_NOTIFIER --group 1 -title "$title" -subtitle "$subtitle" -message "$message" -open "$link" -appIcon "$icon"
}
4 changes: 2 additions & 2 deletions lib/remote_gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function do_github_remote_call() {
local url=$1
local access_token=$2
local response
response=$(curl -w "%{http_code}" $url -H "Authorization: token $access_token" 2>/dev/null)
response=$(curl -w "%{http_code}" "$url" -H "Authorization: token $access_token" 2>/dev/null)
local call_result=$?
if [[ $call_result -ne 0 ]]; then
echo "Failed to connect to $url"
Expand All @@ -25,6 +25,6 @@ function do_github_remote_call() {
return 1
fi
fi
echo $response_body
echo "$response_body"
return 0
}
6 changes: 3 additions & 3 deletions lib/url.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

function assert_is_valid_github_or_ghe_base_url() {
local url=$1
if [[ $(echo $url | grep -cE 'https://([-A-Za-z0-9\+&@#_]*\.)+[-A-Za-z0-9]+$') -eq 0 ]]; then
if [[ $(echo "$url" | grep -cE 'https://([-A-Za-z0-9\+&@#_]*\.)+[-A-Za-z0-9]+$') -eq 0 ]]; then
echo "The url is not a valid. Valid example should be like https://github.com"
exit
fi
}

function get_resource_name() {
local url=$1
assert_is_valid_github_or_ghe_base_url $url
echo ${url##https://}
assert_is_valid_github_or_ghe_base_url "$url"
echo "${url##https://}"
}
2 changes: 1 addition & 1 deletion test/notifier_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function test_with_multiline_body() {
local message="line 1
line 2"
show_notification_window title subtitle "$message" link icon
verify_with_all_args terminal_notifier "--group 1 -title title -subtitle subtitle -message line 1 line 2 -open link -appIcon icon"
verify_with_all_args terminal_notifier "--group 1 -title title -subtitle subtitle -message $message -open link -appIcon icon"
}

function test_when_invalid_characters_are_used_for_terminal_notifier() {
Expand Down

0 comments on commit 28f2577

Please sign in to comment.