Skip to content

Instantly share code, notes, and snippets.

@trivelt
Last active August 18, 2018 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trivelt/afd9a762e5cccf87fcefe0c9b04f6772 to your computer and use it in GitHub Desktop.
Save trivelt/afd9a762e5cccf87fcefe0c9b04f6772 to your computer and use it in GitHub Desktop.
#!/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