Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
enable_bracketed_mode() {
printf "\e[?2004h"
}
disable_bracketed_mode() {
printf "\e[?2004l"
}
enable_bracketed_mode
echo "Insert any text"
stty -echo
read someText
stty echo
start="\e[200~"
end="\e[201~"
if [[ $someText == `echo -en "$start*$end"` ]]; then
length=${#someText}
length=$((length-12))
someText=${someText:6:length}
echo "You pasted text '$someText'"
else
echo "You entered text '$someText'"
fi
disable_bracketed_mode
#!/bin/bash
# Source: https://www.linuxquestions.org/questions/linux-software-2/bash-scripting-pipe-input-to-script-vs-%241-570945/
# To distinguish between entered and pasted text use 'bracketed paste mode'
read someInput
if readlink /proc/$$/fd/0 | grep -q "^pipe:"; then
echo "Pipe input"
elif file $( readlink /proc/$$/fd/0 ) | grep -q "character special"; then
echo "Standard input"
else
echo "File input"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.