Skip to content

Instantly share code, notes, and snippets.

@eric-glb
Last active August 6, 2023 20:27
Show Gist options
  • Select an option

  • Save eric-glb/0291877675663ed0a17cea1d029ebdb9 to your computer and use it in GitHub Desktop.

Select an option

Save eric-glb/0291877675663ed0a17cea1d029ebdb9 to your computer and use it in GitHub Desktop.
Bash: show a notification in the terminal's last line
write_message() {
local message
message=" ${*} "
__write() {
local reset col_bg col_fg
reset="$(tput sgr0)"
col_bg="$(tput setab 4)"
col_fg="$(tput setaf 0)"
[[ "${2-}" == "--no-background" ]] && unset col_bg
tput sc
tput cup "${LINES}" "$((COLUMNS - ${#message}))"
printf "${col_bg}${col_fg}%s${reset}" "${message}"
tput rc
}
__clean_up() {
local blank_spaces
blank_spaces="$(printf "%${#message}s")"
sleep 5
__write "${blank_spaces}" --no-background
}
__write "${message}"
(__clean_up &)
unset -f __write __clean_up
}
@eric-glb
Copy link
Author

eric-glb commented Aug 6, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment