Skip to main content
Code Review

Return to Question

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link
minor typo
Source Link
Matt
  • 143
  • 5
#!/usr/bin/env bash
#.-----.-----.-----.--------.---.-.-----.
#|__ --| _ | _ | | _ | |
#|_____|_____| __|__|__|__|___._|__|__|
# |__| Matthew A. Brassey
version=1.0.0
license="
sopman v${version}
Copyright (C) 2017 Matthew A. Brassey
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program. If not, see <http://www.gnu.org/licenses/>.
"
help="
Usage: ./sopman.sh [--help|--version]
[options]
 --search Search sopman archive for a string. '--search <search string>'
 --motd Display message of the day.
 --license Show lisense information.
"
#Variables
args=("$@")
sops=(sops/*.sopman.txt)
stoploop="false"
endscript="false"
length="${#sops[@]}"
#Colors
lineColor='\e[0m'
reset="\e[0m";
black="\e[1;30m";
blue="\e[1;34m";
cyan="\e[1;36m";
green="\e[1;32m";
purple="\e[1;35m";
red="\e[1;31m";
white="\e[1;37m";
yellow="\e[1;33m";
header="$(echo -e "${cyan}================================================================[sopman]====${reset}")"
footer="$(echo -e "${cyan}============================================================================${reset}")"
#Functions
function search() {
 echo -e "${green}Search results for \"$searchString\":${reset}\n"
 grep -rnw sops/ -e "$searchString" --include "*.sopman.txt"
}
function motd() {
 clear
 echo "$header"
 while read -r line; do
 GETCOLOR "$line"
 newLine=$(echo "$line" | sed "s/+[a-Z]\++//g")
# shopt -s extglob
# new_line=${line//(\+)}
 echo -e "${lineColor}${newLine}${reset}"
 done <"motd"
 echo "$footer"
}
function menu0 {
 fcount="0"
 clear
 echo "$header"
 motd
 echo -e "${green}0)0] Search ${reset}"
 for sop in "${sops[@]}"
 do
 let fcount=fcount+1
 echo -e "${green}$fcount) ${sop:5:-11} ${reset}"
 done
 echo "$footer"
}
function GETCOLOR() {
 if [[ 1ドル =~ \+[a-Z]+\+? ]]; then
 local match=${BASH_REMATCH[0]};
 case $match in
 "+black+") lineColor=$black;;
 "+red+") lineColor=$red;;
 "+green+") lineColor=$green;;
 "+blue+") lineColor=$blue;;
 "+purple+") lineColor=$purple;;
 "+cyan+") lineColor=$cyan;;
 "+yellow+") lineColor=$yellow;;
 "+white+") lineColor=$white;;
 *) lineColor=$reset;;
 esac
 fi
}
for ((arg=0;arg<"${#args[@]}";arg++)); do
 [ "${args[$arg]}" == "--version" ] && echo "${version}" && exit
 [ "${args[$arg]}" == "--help" ] && echo "${help}" && exit
 [ "${args[$arg]}" == "--license" ] && echo "${license}" && exit
 [ "${args[$arg]}" == "--search" ] && searchString=${args[$arg+1]} && clear && echo "$header" && search && echo "$footer" && exit
 [ "${args[$arg]}" == "--motd" ] && clear && echo "$header" && motd && exit
 #[ "${args[$arg]}" == "--" ] && echo ${args[$arg]}
done
while [ $endscript = "false" ]
do
 menu0 
 while [ $stoploop = "false" ]
 do
 printf "Enter your selection (q to quit) : "
 read -r input1
 if [ "$input1" = "q" ]; then
 echo -e "${cyan}Bye-Bye${reset}"
 exit
 fi
 if [ "$input1" -eq "0" ]; then
 printf "Search for: "
 read -r searchString
 clear
 echo "$header"
 search
 echo "$footer"
 printf "[ 'm' to return to menu, anything else to quit ] : "
 read -r input3
 if [ "$input3" = "m" ]; then
 break
 else 
 echo -e "${cyan}Bye-Bye${reset}"
 exit
 fi
 fi
 if [ "$input1" -ge "1" ] && [ "$input1" -le "$length" ]; then
 clear
 echo "$header"
 while read -r line; do
 GETCOLOR "$line"
 newLine=$(echo "$line" | sed "s/+[a-Z]\++//g")
 echo -e "${lineColor}${newLine}${reset}"
 done <"${sops[$input1-1]}"
 echo "$footer"
 printf "[ 'm' to return to menu, anything else to quit ] : "
 read -r input2
 if [ "$input2" = "m" ]; then
 break
 else
 echo -e "${cyan}Bye-Bye${reset}"
 exit
 fi
 else
 echo -e "${red}ERROR! Please select an option : ${reset}"
 retryCount=$((retryCount+1))
 if [ "$retryCount" -ge "3" ]; then
 echo -e "${red}EXIT!${reset}"
 exit
 fi
 fi
 done
done
#!/usr/bin/env bash
#.-----.-----.-----.--------.---.-.-----.
#|__ --| _ | _ | | _ | |
#|_____|_____| __|__|__|__|___._|__|__|
# |__| Matthew A. Brassey
version=1.0.0
license="
sopman v${version}
Copyright (C) 2017 Matthew A. Brassey
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program. If not, see <http://www.gnu.org/licenses/>.
"
help="
Usage: ./sopman.sh [--help|--version]
[options]
 --search Search sopman archive for a string. '--search <search string>'
 --motd Display message of the day.
 --license Show lisense information.
"
#Variables
args=("$@")
sops=(sops/*.sopman.txt)
stoploop="false"
endscript="false"
length="${#sops[@]}"
#Colors
lineColor='\e[0m'
reset="\e[0m";
black="\e[1;30m";
blue="\e[1;34m";
cyan="\e[1;36m";
green="\e[1;32m";
purple="\e[1;35m";
red="\e[1;31m";
white="\e[1;37m";
yellow="\e[1;33m";
header="$(echo -e "${cyan}================================================================[sopman]====${reset}")"
footer="$(echo -e "${cyan}============================================================================${reset}")"
#Functions
function search() {
 echo -e "${green}Search results for \"$searchString\":${reset}\n"
 grep -rnw sops/ -e "$searchString" --include "*.sopman.txt"
}
function motd() {
 clear
 echo "$header"
 while read -r line; do
 GETCOLOR "$line"
 newLine=$(echo "$line" | sed "s/+[a-Z]\++//g")
# shopt -s extglob
# new_line=${line//(\+)}
 echo -e "${lineColor}${newLine}${reset}"
 done <"motd"
 echo "$footer"
}
function menu0 {
 fcount="0"
 clear
 echo "$header"
 motd
 echo -e "${green}0) Search ${reset}"
 for sop in "${sops[@]}"
 do
 let fcount=fcount+1
 echo -e "${green}$fcount) ${sop:5:-11} ${reset}"
 done
 echo "$footer"
}
function GETCOLOR() {
 if [[ 1ドル =~ \+[a-Z]+\+? ]]; then
 local match=${BASH_REMATCH[0]};
 case $match in
 "+black+") lineColor=$black;;
 "+red+") lineColor=$red;;
 "+green+") lineColor=$green;;
 "+blue+") lineColor=$blue;;
 "+purple+") lineColor=$purple;;
 "+cyan+") lineColor=$cyan;;
 "+yellow+") lineColor=$yellow;;
 "+white+") lineColor=$white;;
 *) lineColor=$reset;;
 esac
 fi
}
for ((arg=0;arg<"${#args[@]}";arg++)); do
 [ "${args[$arg]}" == "--version" ] && echo "${version}" && exit
 [ "${args[$arg]}" == "--help" ] && echo "${help}" && exit
 [ "${args[$arg]}" == "--license" ] && echo "${license}" && exit
 [ "${args[$arg]}" == "--search" ] && searchString=${args[$arg+1]} && clear && echo "$header" && search && echo "$footer" && exit
 [ "${args[$arg]}" == "--motd" ] && clear && echo "$header" && motd && exit
 #[ "${args[$arg]}" == "--" ] && echo ${args[$arg]}
done
while [ $endscript = "false" ]
do
 menu0 
 while [ $stoploop = "false" ]
 do
 printf "Enter your selection (q to quit) : "
 read -r input1
 if [ "$input1" = "q" ]; then
 echo -e "${cyan}Bye-Bye${reset}"
 exit
 fi
 if [ "$input1" -eq "0" ]; then
 printf "Search for: "
 read -r searchString
 clear
 echo "$header"
 search
 echo "$footer"
 printf "[ 'm' to return to menu, anything else to quit ] : "
 read -r input3
 if [ "$input3" = "m" ]; then
 break
 else 
 echo -e "${cyan}Bye-Bye${reset}"
 exit
 fi
 fi
 if [ "$input1" -ge "1" ] && [ "$input1" -le "$length" ]; then
 clear
 echo "$header"
 while read -r line; do
 GETCOLOR "$line"
 newLine=$(echo "$line" | sed "s/+[a-Z]\++//g")
 echo -e "${lineColor}${newLine}${reset}"
 done <"${sops[$input1-1]}"
 echo "$footer"
 printf "[ 'm' to return to menu, anything else to quit ] : "
 read -r input2
 if [ "$input2" = "m" ]; then
 break
 else
 echo -e "${cyan}Bye-Bye${reset}"
 exit
 fi
 else
 echo -e "${red}ERROR! Please select an option : ${reset}"
 retryCount=$((retryCount+1))
 if [ "$retryCount" -ge "3" ]; then
 echo -e "${red}EXIT!${reset}"
 exit
 fi
 fi
 done
done
#!/usr/bin/env bash
#.-----.-----.-----.--------.---.-.-----.
#|__ --| _ | _ | | _ | |
#|_____|_____| __|__|__|__|___._|__|__|
# |__| Matthew A. Brassey
version=1.0.0
license="
sopman v${version}
Copyright (C) 2017 Matthew A. Brassey
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program. If not, see <http://www.gnu.org/licenses/>.
"
help="
Usage: ./sopman.sh [--help|--version]
[options]
 --search Search sopman archive for a string. '--search <search string>'
 --motd Display message of the day.
 --license Show lisense information.
"
#Variables
args=("$@")
sops=(sops/*.sopman.txt)
stoploop="false"
endscript="false"
length="${#sops[@]}"
#Colors
lineColor='\e[0m'
reset="\e[0m";
black="\e[1;30m";
blue="\e[1;34m";
cyan="\e[1;36m";
green="\e[1;32m";
purple="\e[1;35m";
red="\e[1;31m";
white="\e[1;37m";
yellow="\e[1;33m";
header="$(echo -e "${cyan}================================================================[sopman]====${reset}")"
footer="$(echo -e "${cyan}============================================================================${reset}")"
#Functions
function search() {
 echo -e "${green}Search results for \"$searchString\":${reset}\n"
 grep -rnw sops/ -e "$searchString" --include "*.sopman.txt"
}
function motd() {
 clear
 echo "$header"
 while read -r line; do
 GETCOLOR "$line"
 newLine=$(echo "$line" | sed "s/+[a-Z]\++//g")
# shopt -s extglob
# new_line=${line//(\+)}
 echo -e "${lineColor}${newLine}${reset}"
 done <"motd"
 echo "$footer"
}
function menu0 {
 fcount="0"
 clear
 echo "$header"
 motd
 echo -e "${green}0] Search ${reset}"
 for sop in "${sops[@]}"
 do
 let fcount=fcount+1
 echo -e "${green}$fcount) ${sop:5:-11} ${reset}"
 done
 echo "$footer"
}
function GETCOLOR() {
 if [[ 1ドル =~ \+[a-Z]+\+? ]]; then
 local match=${BASH_REMATCH[0]};
 case $match in
 "+black+") lineColor=$black;;
 "+red+") lineColor=$red;;
 "+green+") lineColor=$green;;
 "+blue+") lineColor=$blue;;
 "+purple+") lineColor=$purple;;
 "+cyan+") lineColor=$cyan;;
 "+yellow+") lineColor=$yellow;;
 "+white+") lineColor=$white;;
 *) lineColor=$reset;;
 esac
 fi
}
for ((arg=0;arg<"${#args[@]}";arg++)); do
 [ "${args[$arg]}" == "--version" ] && echo "${version}" && exit
 [ "${args[$arg]}" == "--help" ] && echo "${help}" && exit
 [ "${args[$arg]}" == "--license" ] && echo "${license}" && exit
 [ "${args[$arg]}" == "--search" ] && searchString=${args[$arg+1]} && clear && echo "$header" && search && echo "$footer" && exit
 [ "${args[$arg]}" == "--motd" ] && clear && echo "$header" && motd && exit
 #[ "${args[$arg]}" == "--" ] && echo ${args[$arg]}
done
while [ $endscript = "false" ]
do
 menu0 
 while [ $stoploop = "false" ]
 do
 printf "Enter your selection (q to quit) : "
 read -r input1
 if [ "$input1" = "q" ]; then
 echo -e "${cyan}Bye-Bye${reset}"
 exit
 fi
 if [ "$input1" -eq "0" ]; then
 printf "Search for: "
 read -r searchString
 clear
 echo "$header"
 search
 echo "$footer"
 printf "[ 'm' to return to menu, anything else to quit ] : "
 read -r input3
 if [ "$input3" = "m" ]; then
 break
 else 
 echo -e "${cyan}Bye-Bye${reset}"
 exit
 fi
 fi
 if [ "$input1" -ge "1" ] && [ "$input1" -le "$length" ]; then
 clear
 echo "$header"
 while read -r line; do
 GETCOLOR "$line"
 newLine=$(echo "$line" | sed "s/+[a-Z]\++//g")
 echo -e "${lineColor}${newLine}${reset}"
 done <"${sops[$input1-1]}"
 echo "$footer"
 printf "[ 'm' to return to menu, anything else to quit ] : "
 read -r input2
 if [ "$input2" = "m" ]; then
 break
 else
 echo -e "${cyan}Bye-Bye${reset}"
 exit
 fi
 else
 echo -e "${red}ERROR! Please select an option : ${reset}"
 retryCount=$((retryCount+1))
 if [ "$retryCount" -ge "3" ]; then
 echo -e "${red}EXIT!${reset}"
 exit
 fi
 fi
 done
done
final code update
Source Link
Matt
  • 143
  • 5
Loading
updated to latest code sample
Source Link
Matt
  • 143
  • 5
Loading
edited body
Source Link
Matt
  • 143
  • 5
Loading
deleted 3 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Loading
added 12 characters in body
Source Link
Matt
  • 143
  • 5
Loading
Source Link
Matt
  • 143
  • 5
Loading
lang-bash

AltStyle によって変換されたページ (->オリジナル) /