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.
echo "supported actions: new (n), check (c)."
return 1
return 2
}
# autocomplete.

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -19,7 +19,7 @@ __prompt_command()
# set error red
if $is_error; then
PS1+="\[${color_red}\]"
PS1+="\[${color_bred}\]"
PS1+="["
else
PS1+="\[${color_default}\]"
@ -44,13 +44,22 @@ __prompt_command()
# set error red
if $is_error; then
PS1+="\[${color_red}\]"
PS1+="\[${color_bred}\]"
PS1+="] "
else
PS1+="\[${color_default}\]"
PS1+="] "
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
PS1+="\n"
PS1+="\[${color_default}\]"
@ -62,3 +71,47 @@ __prompt_command()
PS1+="$ "
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.
if [[ "$(ffmpeg -version)" = "" ]] || [[ "$(ffprobe -version)" = "" ]]; then
echo -e "${color_red}ffmpeg and ffprobe are required.${color_default}"
return 2
return 1
fi
local target="${@}" # What to download/update.
@ -17,7 +17,7 @@ vdl()
if [[ "${target}" = "" ]]; then
echo -e "${color_red}Could not determine [LINK] to download.${color_default}"
echo "Usage: vdl [LINK]"
return 1
return 2
fi
# Save [LINK] for later use.