@@ -118,16 +118,43 @@ run_script() {
118118 fi
119119}
120120
121+ ds_version () {
122+ local Branch Version
123+ pushd " ${SCRIPTPATH} " & > /dev/null || fatal " Failed to change directory.\nFailing command: ${F[C]} pushd \" ${SCRIPTPATH} \" "
124+ git fetch --quiet & > /dev/null || true
125+
126+ # Get the branch
127+ Branch=" $( git symbolic-ref --short -q HEAD 2> /dev/null || true) "
128+ # Get the current tag. If no tag, use the commit instead.
129+ Version=" $( git describe --tags --exact-match 2> /dev/null || true) "
130+ if [[ -z ${Version-} ]]; then
131+ Version=" commit $( git rev-parse --short HEAD 2> /dev/null || true) "
132+ fi
133+
134+ echo " ${Branch-} ${Version-} "
135+ popd & > /dev/null
136+ }
137+ ds_update_available () {
138+ pushd " ${SCRIPTPATH} " & > /dev/null || fatal " Failed to change directory.\nFailing command: ${F[C]} pushd \" ${SCRIPTPATH} \" "
139+ git fetch --quiet & > /dev/null
140+ local -i result=0
141+ # shellcheck disable=SC2319 # This $? refers to a condition, not a command. Assign to a variable to avoid it being overwritten.
142+ [[ $( git rev-parse HEAD 2> /dev/null) != $( git rev-parse ' @{u}' 2> /dev/null) ]] || result=$?
143+ popd & > /dev/null
144+ return ${result}
145+ }
146+
147+
121148declare -x APPLICATION_VERSION
122- APPLICATION_VERSION=" $( run_script ' ds_version' ) "
149+ APPLICATION_VERSION=" $( ds_version) "
123150readonly APPLICATION_VERSION
124151
125152usage () {
126153 local APPLICATION_HEADING=" ${APPLICATION_NAME} "
127154 if [[ ${APPLICATION_VERSION-} ]]; then
128155 APPLICATION_HEADING+=" [${APPLICATION_VERSION} ]"
129156 fi
130- if run_script ' ds_update_available' ; then
157+ if ds_update_available; then
131158 APPLICATION_HEADING+=" (Update Available)"
132159 fi
133160 cat << EOF
@@ -633,7 +660,7 @@ _dialog_() {
633660
634661 CleanRightBackTitle=' '
635662 RightBackTitle=' '
636- if run_script ' ds_update_available' ; then
663+ if ds_update_available; then
637664 CleanRightBackTitle=" (Update Available)"
638665 RightBackTitle=" ${DC[ApplicationUpdateBrackets]} (${DC[ApplicationUpdate]} Update Available${DC[ApplicationUpdateBrackets]} )${DC[NC]} "
639666 fi
@@ -810,7 +837,7 @@ main() {
810837 run_script ' symlink_ds'
811838 # Apply the GUI theme
812839 run_script ' apply_theme'
813- if run_script ' ds_update_available' ; then
840+ if ds_update_available; then
814841 notice " An update to ${APPLICATION_NAME} is available. Run 'ds -u' to update."
815842 fi
816843 # Execute CLI Argument Functions
0 commit comments