Shell script doesn't clear temporary output upon exit
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Shell script doesn't clear temporary output upon exit
Greetings!
There is a shell script called 'fasd' which takes several letters of a directory name, displays in a temporary menu a list of matching directory full names, reads a number of selected item from user and cd's to the selected directory.
The temporary menu was disapperaring from the screen until recently. I'm using Arch and after a recent system upgrade the script changed it's behaviour and the temporary menu is not disappearing anymore after script's exit. The script itself was not updated, so I guess an update in some library has caused this change.
My question is: what is the shell mechanism which was causing the temporary menu to be cleared on exit in that script?
It's rather convoluted, so below is an approximate description of it's working in the part relevant to the temporary menu.
The script is called with 'zz <dirname>' command. 'zz' is an alias to the 'fasd_cd' shell function.
1. The shell function fasd_cd, takes the argument and calls the script with it and additionaly with '-e printf %s' parameter which means simply to print the result to stdout on exit. (This function takes one argument which is a shortened (fuzzy) name of a directory to cd into.)
2. Script queries its directory database with the fuzzy directory name and prints the query result, which is a list of full directory names similar to the fuzzy one, as a temporary menu and reads the user's input with a menu item number:
This will clear the previous content of the screen, which remained intact when the menu was disappearing.
I see, it is not just de-cluttering the display, you want to see the original stuff?
I would look into the utils and moreutils. "dialog" and "whiptail" come to mind, but I am not sure that they will serve. Having the script open a new terminal for display, and closing it on exit might do, but I have not tested the technique.
That's good idea, but if to look into the original solution: there is thing in Unix terminals called "alternate display", which causes the program's output to be cleared after it's exit and to restore the previous terminal's screen. This behaviour can be triggered by a command ot terminal sequence:
In that script (fasd) I don't see any similar command is called anywhere. So maybe some default settings somewhere were such, that the temporary script's output was cleared after exit, and then maybe some defaults somewhere were changed?
That's good idea, but if to look into the original solution: there is thing in Unix terminals called "alternate display", which causes the program's output to be cleared after it's exit and to restore the previous terminal's screen. This behaviour can be triggered by a command ot terminal sequence:
In that script (fasd) I don't see any similar command is called anywhere. So maybe some default settings somewhere were such, that the temporary script's output was cleared after exit, and then maybe some defaults somewhere were changed?
I had not seen that article, that is very interesting.
Why not try wrapping your script output in those tput lines to get that effect? Have you tried that yet?
In that script (fasd) I don't see any similar command is called anywhere. So maybe some default settings somewhere were such, that the temporary script's output was cleared after exit, and then maybe some defaults somewhere were changed?
it says right there in the accepted answer that you can use escape sequences to achieve the same.
checked for those (be aware; there's different ways to integrate them in a script; best if youjust search for '1049h')?
edit:
your edit:
well, you (your term) don't have that ability (man termcap).
if fasd works as intended, it achieves the same some other way.
maybe ncurses?
maybe use more variables to hold the values you want to keep, then print them out as needed. Maybe using the 'clear' command to clear the screen then a function call to "print" everything you need back to the screen when you need it placed there.
if fasd works as intended, it achieves the same some other way.
maybe ncurses?
Well fasd worked as intended, but doesn't work anymore after a recent system update (I'm on rolling-release Arch). This question is about what has caused the change.
fasd doesn't use ncurses, you can take a look at it through the link in one of above posts.
Well fasd worked as intended, but doesn't work anymore after a recent system update (I'm on rolling-release Arch). This question is about what has caused the change.
aah, now we're getting somewhere!
i just installed fast-git and nothing happens when i first
Code:
To use, run the following: eval "$(fasd --init auto)"
and then
Code:
fast -i
:-(
the normal command prompt just returns, as if i entered "true".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.