Last active
August 18, 2018 11:45
-
-
Save trivelt/afd9a762e5cccf87fcefe0c9b04f6772 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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