[enh] It should be able to read from piped content
This commit is contained in:
parent
3974567080
commit
0adaf05483
23
changelog.sh
23
changelog.sh
@ -4,7 +4,9 @@
|
|||||||
|
|
||||||
APP_PATH=$( cd $(dirname ${BASH_SOURCE[0]}) && pwd )
|
APP_PATH=$( cd $(dirname ${BASH_SOURCE[0]}) && pwd )
|
||||||
APP_NAME=$( basename ${BASH_SOURCE[0]})
|
APP_NAME=$( basename ${BASH_SOURCE[0]})
|
||||||
|
STDIN=$( cat )
|
||||||
|
ls -lh /proc/self/fd
|
||||||
|
exec 0</dev/tty
|
||||||
CHANGELOG=/etc/changelog
|
CHANGELOG=/etc/changelog
|
||||||
# %CONFIG% This comment is used to build custom scripts
|
# %CONFIG% This comment is used to build custom scripts
|
||||||
[[ -f "$APP_PATH/config.sh" ]] && source "$APP_PATH/config.sh"
|
[[ -f "$APP_PATH/config.sh" ]] && source "$APP_PATH/config.sh"
|
||||||
@ -22,6 +24,8 @@ CHANGELOG=/etc/changelog
|
|||||||
msg(){ echo -e "$@"; }
|
msg(){ echo -e "$@"; }
|
||||||
panic(){ msg "${@} Exiting."; exit 1;}
|
panic(){ msg "${@} Exiting."; exit 1;}
|
||||||
ENTRY_FILE=$(mktemp)
|
ENTRY_FILE=$(mktemp)
|
||||||
|
|
||||||
|
# This is the main function
|
||||||
change(){
|
change(){
|
||||||
TMP="$1"
|
TMP="$1"
|
||||||
while true ; do
|
while true ; do
|
||||||
@ -48,9 +52,6 @@ change(){
|
|||||||
read -e -i "n" -p "Another section? [yN]:" END
|
read -e -i "n" -p "Another section? [yN]:" END
|
||||||
[[ "${END^^}" == "N" ]] && break
|
[[ "${END^^}" == "N" ]] && break
|
||||||
done
|
done
|
||||||
echo -e "\nHere is the content you are about to add.\n\n$(cat $TMP)\n"
|
|
||||||
read -e -p "OK? [Yn]: " -i y RETURN
|
|
||||||
[[ "N" == ${RETURN^^} ]] && return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template(){
|
template(){
|
||||||
@ -112,11 +113,21 @@ echo -e "\nWelcome to Serious Changelogs Inc. Do you have something for me?\n"
|
|||||||
# check changelog exists
|
# check changelog exists
|
||||||
[[ ! -f "$CHANGELOG" ]] && template "* Changelog: Added $CHANGELOG file\nIt was not serious. Fixed!\n\n" > "$CHANGELOG"
|
[[ ! -f "$CHANGELOG" ]] && template "* Changelog: Added $CHANGELOG file\nIt was not serious. Fixed!\n\n" > "$CHANGELOG"
|
||||||
|
|
||||||
# parse command
|
# Detect piped content
|
||||||
|
if [[ -n "$STDIN" ]] ; then
|
||||||
|
echo -e "$STDIN" > $ENTRY_FILE
|
||||||
|
|
||||||
|
#OR enter interactive mode
|
||||||
|
else
|
||||||
change "$ENTRY_FILE"
|
change "$ENTRY_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
[[ $? -eq 0 ]] && exit
|
# confirm the output
|
||||||
|
echo -e "\nHere is the content you are about to add:\n\n$(cat $ENTRY_FILE)\n"
|
||||||
|
read -e -p "OK? [Yn]: " -i y RETURN
|
||||||
|
[[ "N" == ${RETURN^^} ]] && exit 1
|
||||||
|
|
||||||
|
# Send data to outputs
|
||||||
for (( i=0; i<${#PLUGIN_OUTPUT_MENU[@]}; i++)) ; do
|
for (( i=0; i<${#PLUGIN_OUTPUT_MENU[@]}; i++)) ; do
|
||||||
echo "${PLUGIN_OUTPUT_MENU[$i]}"
|
echo "${PLUGIN_OUTPUT_MENU[$i]}"
|
||||||
${PLUGIN_OUTPUT[$i]} $ENTRY_FILE
|
${PLUGIN_OUTPUT[$i]} $ENTRY_FILE
|
||||||
|
Loading…
Reference in New Issue
Block a user