Skip to content

Instantly share code, notes, and snippets.

@seveibar
Last active August 29, 2015 14:02
Show Gist options
  • Save seveibar/f9c507ad95ac3244b4be to your computer and use it in GitHub Desktop.
Save seveibar/f9c507ad95ac3244b4be to your computer and use it in GitHub Desktop.
Constantly feeds user input to given command and displays output
#!/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