Advertisement
Guest User

Untitled

a guest
May 5th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. $ printf "abc" > some-file
  2. $ cat some-file
  3. abc$
  4.  
  5. # injects the arguments into the terminal, from the second link
  6. function inject() {
  7. perl -e 'ioctl(STDIN, 0x5412, $_) for split "", join " ", @ARGV' "$@"
  8. }
  9. # prints a newline if the cursor is not in position 1
  10. clear_newline() {
  11. local curpos # local variable to hold the cursor position
  12. local input # local variable to hold entered input
  13. stty -echo # disable echoing
  14. inject '
  15. ' # inject a newline to terminate entered input, '' didn't work?
  16. IFS='n' read -s input # read entered input
  17. echo -en '33[6n'
  18. # ask the terminal driver to print the current cursor position
  19. IFS=';' read -d R -a curpos # read cursor position
  20. stty echo # enable echoing
  21. (( curpos[1] > 1 )) && echo -e '33[7m%33[0m'
  22. # if cursor not in first column, print a % with inverted colours and a newline
  23. stty -echo # disable echoing of input to terminal again
  24. inject "${input}" # inject stored input
  25. stty echo # enable echo
  26. }
  27.  
  28. PROMPT_COMMAND='clear_newline' # run clear_newline for every prompt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement