I use the following script to display a dialog in the bash shell:
#!/bin/bash
TFILE=/tmp/habitat_resp_`whoami`.$$
dialog --menu "Commander?" 20 50 10 \
1 "MySQL" \
2 "Apache" \
3 "Postfix" \
4 "Dovecot" \
5 "Owncloud" \
2> $TFILE
# get response
RESPONSE=$(cat $TFILE)
echo $RESPONSE
clear
The problem is, when I scroll up, i can still see the dialog in my scrollback. I want it like vi. I open my script and the dialog appears and if the script is over you cant see the dialog in scrollback.
How can this be achieved?
Regards
S.
Add the --keep-tite option, which tells dialog to use the "alternative screen", which doesn't participate in terminal scrollback. This produces some slightly annoying display artefacts, but possibly not as annoying as polluting your scrollback.
Related
I have a shell script that I run from Xcode to open the root folder in the Terminal. It works as expected when invoked by a function key in Xcode and opens a Terminal window pointing to the value of $SRCROOT as defined in Xcode and an alert with the expected message appears before that.
#! /bin/bash
osascript -e 'display dialog "message" with title "Hi"'
open -a Terminal "$SRCROOT"
Yet when I try to replace "message" to display the contents of $SRCROOT, the dialog doesn't display at all. I've tried all of the approaches listed in the solutions here: osascript using bash variable with a space
Using any of those approaches results in the alert not displaying at all.
I even tried to display the contents of $SRCROOT in a notification with various methods of escaping it but that just displays an empty notification.
Any ideas? TIA.
Save following in test.sh :
#!/usr/bin/env bash
SRCROOT=~/Developer/SwiftVC
osascript \
-e "on run(argv)" \
-e 'display dialog item 1 of argv with title "Hi"' \
-e "end" \
-- "$SRCROOT"
open -a Terminal "$SRCROOT"
and run it with :
chmod +x test.sh
./test.sh
I've been trying to get git-clone to provide output to a textbox in dialog. I tried something like this:
git clone github.com/CrazyWillBear/yes-replacement 2> /tmp/clone.log &
dialog --title "Cloning repo..." --textbox /tmp/clone.log 50 100
It doesn't work and usually displays nothing, writes to the terminal, or just the first line of the output. A loop doesn't work either, it creates some really funky problems.
The result I'm trying to get is this but with the entire output instead of just the first line: example
Use tee to write the output to a file, then use the tailbox feature on dialog to read it live.
git clone https://github.com/CrazyWillBear/pig --progress 2>&1 | tee -a /tmp/clone.$$ &> /dev/null &
dialog --title "Progress" --tailbox /tmp/clone.$$ 50 100
I just wrote a bash script to change PHP-cli and Apache PHP versions without having to manually run dismod or enmod etc etc, and for the script to restart Apache to make the changes, and being that the script uses a case statement, I have a problem in that when the code inside the choice is finished the entire script ends, ie:-
case $CHOICE in
1) do code;;
2) do code;;
esac
So when either choice of 1 or 2 is chosen, the script inside choices is executed, then the script is ended, but I want to restart the script unless the 'Cancel' button is pressed in the dialog box, ie:-
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[#]}" \
2>&1 >/dev/tty)
I have tried adding the script name as an extra line before the ;; but it still stops.
To give an idea, the code I have written is to big to post here, but I'll post it to pastebin and post the link here:-
https://pastebin.com/q2iH7Q2E
As can be seen, I had to add extra case lines at the end of the script, but I want to remove those and have the script rerun after any of the selections are made.
Put a loop around all the code.
while :
do
# all the code that should repeat goes here
done
Inside the loop you can use break to stop the loop.
In Ubuntu 14.10, I would like to display a notification with an icon from the current system theme. In the following code, line 3 is an example of what I mean:
1 #!/bin/bash
2 # Display a notification with an icon
3 ICON="$(somehow-get-path-to-system-theme-root-dir)/rest/of/path/to/icon.svg"
4 notify-send -i $ICON "Some notification text"
Does such a command exist, and if so, what is it?
I think you should do something like this
#!/bin/bash
# Display a notification with an icon
THEME=$(gsettings get org.gnome.desktop.interface icon-theme | tr -d "'")
ICON="/usr/share/icons/${THEME}/rest/of/path/to/icon.svg"
notify-send -i $ICON "Some notification text"
According to the docs for the Unix "screen" command, you can configure it in .screenrc to start with a bunch of default screens, each running a command that you specify.
Here's my cofig:
# Default screens
screen -t "shell_0" 1
screen -t "autotest" 2 cd ~/project/contactdb ; autotest
It will not run the autotest command. That window where I'm trying to run autotest just closes instantly when I start screen.
I also tried it with just...
screen -t "autotest" 2 cd ~/project/contactdb
Same result.
I also tried...
screen -t "autotest" 2 ls
Same result there too.
What's the secret to getting it to run a command in a given screen on startup?
Your program is being run (well, except the cd), it's just that it's being run without a parent shell, so as soon as it completes, it exits and you're done.
You could do:
screen -t "autotest" 2 bash -c 'cd ~/project/contactdb ; autotest'
Spawns two shells, but life will probably go on.
Try this:
$ screen -S 'tailf messages' -d -m tailf /var/log/messages
Then later you can do:
$ screen -ls
1234.tailf messages
Followed by:
$screen -r 1234
This might help but may not be entirely what you want.
Put "zombie az" or "defzombie az" as the first line of your .screenrc. "az" can be whatever 2 keys you'd like. Now, when a screen ought to close (command finished executing, for instance), it won't actually close; hitting 'a' will close it, hitting 'z' will re-execute the command attached to that screen.
I found that at the screen user's manual.
You can also "stuff" characters into the screen as if you had typed them.
Here's how you can do that with your example:
screen -t "shell_0" 1
# create the following screen in the desired dir, instead of cd-ing afterwards :)
chdir ~/project/contactdb
screen -t "autotest" 2
# (without this sometimes screens fail to start correctly for me)
sleep 5
# paste some text into screen number 2:
select 2
stuff "autotest\012"
Here's how mine looks. It seems to work fine. I think either the parenthesis might be causing the problem or screen will not open a window if the command "autotest" does not exist.
screen -t zsh 1
screen -t emacs 2 emacs -nw
screen -t mutt 3 mutt
monitor on
screen -t mc 4 mc -s
screen -t elinks 4 elinks
Here's how I'd do it.
screen -t shell_0
chdir ~/project/contactdb
screen -t autotest autotest
The above appears to be evaluated procedurally by screen. First we establish a new screen with the title shell_0. Since we gave no other options, current working directory will be that of the parent shell or the user's home directory. We then set the default directory for new screens to ~/project/contactdb. Next, we establish a new screen running the autotest command.
Window number (n) is optional, I generally omit it.