PS1 : show exit codes.

This commit is contained in:
Dmitry Voronin 2023-11-20 18:39:04 +03:00
parent edec4202ac
commit 721244896c
8 changed files with 68 additions and 15 deletions

View file

@ -25,7 +25,7 @@ checksum()
# error on wrong action. # error on wrong action.
echo "supported actions: new (n), check (c)." echo "supported actions: new (n), check (c)."
return 1 return 2
} }
# autocomplete. # autocomplete.

View file

@ -9,7 +9,7 @@ convert() {
# Report no output. # Report no output.
if [[ "${to}" = "" ]]; then if [[ "${to}" = "" ]]; then
echo -e "${color_bred}no output file/format.${color_default}" echo -e "${color_bred}no output file/format.${color_default}"
return 1 return 2
fi fi
# Report no input. # Report no input.
@ -28,7 +28,7 @@ convert() {
;; ;;
*) *)
echo -e "${color_yellow}Conversion ${from}-${to} not supported.${color_default}" echo -e "${color_yellow}Conversion ${from}-${to} not supported.${color_default}"
return 3 return 1
;; ;;
esac esac

View file

@ -8,7 +8,7 @@ fix_ethernet_speed()
if [[ "${device}" = "" || "${speed}" = "" ]]; then if [[ "${device}" = "" || "${speed}" = "" ]]; then
echo "usage: fix_ethernet_speed <DEVICE> <SPEED>" echo "usage: fix_ethernet_speed <DEVICE> <SPEED>"
return 1 return 2
fi fi
ethtool -s "${device}" speed "${speed}" ethtool -s "${device}" speed "${speed}"

View file

@ -60,7 +60,7 @@ gu()
if [[ "${name}" = "" || "${email}" = "" ]]; then if [[ "${name}" = "" || "${email}" = "" ]]; then
echo "usage: gu [EMAIL]" echo "usage: gu [EMAIL]"
return 1 return 2
fi fi
git config user.name "${name}" git config user.name "${name}"

View file

@ -181,7 +181,7 @@ name_series()
# error when no season number specified. # error when no season number specified.
if [[ "${season}" = "" ]]; then if [[ "${season}" = "" ]]; then
echo "usage: name_series <SEASON> [FILES]" echo "usage: name_series <SEASON> [FILES]"
return 1 return 2
fi fi
# all targets by default. # all targets by default.
@ -239,7 +239,7 @@ name_manga()
# error when no season number specified. # error when no season number specified.
if [[ "${season}" = "" ]]; then if [[ "${season}" = "" ]]; then
echo "usage: name_manga <SEASON> [FILES]" echo "usage: name_manga <SEASON> [FILES]"
return 1 return 2
fi fi
# all targets by default. # all targets by default.
@ -295,7 +295,7 @@ name_ext()
# error when no new extension specified. # error when no new extension specified.
if [[ "${extension}" = "" ]]; then if [[ "${extension}" = "" ]]; then
echo "usage: name_ext <EXTENSION> [FILES]" echo "usage: name_ext <EXTENSION> [FILES]"
return 1 return 2
fi fi
# all targets by default. # all targets by default.

View file

@ -12,7 +12,7 @@ pack()
# report no output. # report no output.
if [[ "${output}" = "" ]]; then if [[ "${output}" = "" ]]; then
echo "Usage: pack <TARGET.ext> <FILES>" echo "Usage: pack <TARGET.ext> <FILES>"
return 1 return 2
fi fi
# report no format. # report no format.
@ -25,7 +25,7 @@ pack()
# report no targets. # report no targets.
if [[ "${targets}" = "" ]]; then if [[ "${targets}" = "" ]]; then
echo "Usage: pack <TARGET.ext> <FILES>" echo "Usage: pack <TARGET.ext> <FILES>"
return 3 return 2
fi fi
# process. # process.
@ -120,7 +120,7 @@ unpack()
;; ;;
*) *)
echo -e "${color_yellow}${target}: format not supported.${color_default}" echo -e "${color_yellow}${target}: format not supported.${color_default}"
return 2 return 1
;; ;;
esac esac

View file

@ -19,7 +19,7 @@ __prompt_command()
# set error red # set error red
if $is_error; then if $is_error; then
PS1+="\[${color_red}\]" PS1+="\[${color_bred}\]"
PS1+="[" PS1+="["
else else
PS1+="\[${color_default}\]" PS1+="\[${color_default}\]"
@ -44,13 +44,22 @@ __prompt_command()
# set error red # set error red
if $is_error; then if $is_error; then
PS1+="\[${color_red}\]" PS1+="\[${color_bred}\]"
PS1+="] " PS1+="] "
else else
PS1+="\[${color_default}\]" PS1+="\[${color_default}\]"
PS1+="] " PS1+="] "
fi fi
# If error, show code.
if ${is_error}; then
PS1+="${color_red}("
PS1+="${last_status}"
local error_type="$(_ps1error ${last_status})"
[[ "${error_type}" != "" ]] && PS1+=" ${error_type}"
PS1+=")${color_default} "
fi
# command on new line # command on new line
PS1+="\n" PS1+="\n"
PS1+="\[${color_default}\]" PS1+="\[${color_default}\]"
@ -62,3 +71,47 @@ __prompt_command()
PS1+="$ " PS1+="$ "
fi fi
} }
_ps1error() {
local type
case ${1} in
1) type="GENERAL" ;;
2) type="MISUSE" ;;
126) type="CANTEXEC" ;;
127) type="CMDNF" ;;
129) type="SIGHUP" ;;
130) type="SIGINT" ;;
131) type="SIGQUIT" ;;
132) type="SIGILL" ;;
133) type="SIGTRAP" ;;
134) type="SIGABRT" ;;
135) type="SIGBUS" ;;
136) type="SIGFPE" ;;
137) type="SIGKILL" ;;
138) type="SIGUSR1" ;;
139) type="SIGSEGV" ;;
140) type="SIGUSR2" ;;
141) type="SIGPIPE" ;;
142) type="SIGALRM" ;;
143) type="SIGTERM" ;;
144) type="" ;;
145) type="SIGCHLD" ;;
146) type="SIGCONT" ;;
147) type="SIGSTOP" ;;
148) type="SIGTSTP" ;;
149) type="SIGTTIN" ;;
150) type="SIGTTOU" ;;
151) type="SIGURG" ;;
152) type="SIGXCPU" ;;
153) type="SIGXFSZ" ;;
154) type="SIGVTALRM" ;;
155) type="SIGPROF" ;;
156) type="SIGWINCH" ;;
157) type="SIGIO" ;;
158) type="SIGPWR" ;;
159) type="SIGSYS" ;;
*) type="" ;;
esac
echo -n "${type}"
}

View file

@ -5,7 +5,7 @@ vdl()
# Check that ffmpeg and ffprobe are available. # Check that ffmpeg and ffprobe are available.
if [[ "$(ffmpeg -version)" = "" ]] || [[ "$(ffprobe -version)" = "" ]]; then if [[ "$(ffmpeg -version)" = "" ]] || [[ "$(ffprobe -version)" = "" ]]; then
echo -e "${color_red}ffmpeg and ffprobe are required.${color_default}" echo -e "${color_red}ffmpeg and ffprobe are required.${color_default}"
return 2 return 1
fi fi
local target="${@}" # What to download/update. local target="${@}" # What to download/update.
@ -17,7 +17,7 @@ vdl()
if [[ "${target}" = "" ]]; then if [[ "${target}" = "" ]]; then
echo -e "${color_red}Could not determine [LINK] to download.${color_default}" echo -e "${color_red}Could not determine [LINK] to download.${color_default}"
echo "Usage: vdl [LINK]" echo "Usage: vdl [LINK]"
return 1 return 2
fi fi
# Save [LINK] for later use. # Save [LINK] for later use.