Last active
August 29, 2015 14:02
-
-
Save seveibar/f9c507ad95ac3244b4be to your computer and use it in GitHub Desktop.
Constantly feeds user input to given command and displays output
This file contains hidden or 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 | |
# feeder script | |
# Constantly feeds user input to given command and displays output | |
fullStr="" | |
while true; do | |
read -n 1 -s nextChar | |
# Check if character is backspace | |
hexChar="$(echo $nextChar | hexdump)" | |
if [[ "$hexChar" =~ .*0a7f.* ]]; then | |
if [[ fullStr = "" ]]; then | |
# If the string is empty, exit the program | |
exit | |
else | |
# Otherwise, remove last character | |
fullStr="${fullStr:0:-1}" | |
fi | |
elif [[ "$hexChar" =~ .*000a.* ]]; then | |
# Space character entered | |
fullStr="$fullStr " | |
else | |
# If not backspace, add character to string | |
fullStr="$fullStr$nextChar" | |
fi | |
clear | |
termHeight="$(stty size | cut -d' ' -f1)" | |
termHeight="$(($termHeight - 6))" | |
echo "$@ $fullStr" | |
echo "----------------------------------------------------" | |
# Run command | |
echo "$($@ $fullStr | head -$termHeight)" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment