I am making a bash function that show a menu binded to pgdown to browse through a a window which list my history (like 4dos/4nt etcetera). I have made so one line is always highlighted.

$pos is where in the history I want the list to start

 $ function hidown (){ if [ "$down" -gt 1 ]; then ((--down)); else down=100; fi ; hismenu_down "$down"; }  
 $ bind -x '"\e[6~":"hidowm"' 
 $ down=100


      function hismenu_down()  
        pos=$1; hilength=10; hirange="$(($hilength+$pos))";  
        hisstring=$(history | tail -n $hirange)
        for ((i=hilength; i>=0;  --i)); do
            if [ $i == 6 ]; then tput setaf 7; else tput setaf 6; fi;
            tput cup $i 55; 
            printf  "$hisstring" | tail -n "$(($i+$pos))" | head -n1 |  cut -c1-105; 
       done; tput sgr0; tput rc;

I would like to have the highlighted text output at command line so I just have to put return or edit the text before I hit return to execute the command.

I will also temporarily bind key esc to remove the code from command line (and possible other actions to delete the code from the history list) and at the same time rebind the same key to afterwards be binded to the its default.

But that part I can clue out for myself. What I am asking for, is only this - how do I put a string to the commandline?

  • Are you just trying to reinvent Ctrl+R? – terdon Apr 5 '16 at 10:26
  • Pretty much. i am trying to create an extended version of Ctrl+r. For now I have the menu worikng and could easily execute the command in the menu But I also want an option to edit that string- prefereble at the commandline. – Swepter Apr 5 '16 at 12:25
  • solved. I am just busy getting the program to work as I want. I will post the solution in a day or two. – Swepter Apr 6 '16 at 20:53
  • Just telling - I will post the solution I worked out. But it will take som more time because my system crashed so made a reinstall with btrfs and for now my main focus is tweaking that system. When so is done I will go on with the stuff around where one of the things is the simple program which was the origin of this question. – Swepter Jul 25 '16 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.