Guake terminal startup shell script - shell

I'm trying to create a startup script to open two tabs in Guake, execute commands, and then rename the tabs. Unfortunately the tabs are not being renamed. Also irritating, it's opening up the terminal in the directory of the shell script instead of the default ~/ directory. After reading the help file, I'm pretty sure that the script is correct.
Help file:
Options:
-h, --help show this help message and exit
-f, --fullscreen Put Guake in fullscreen mode
-t, --toggle-visibility
Toggles the visibility of the terminal window
-p, --preferences Shows Guake preference window
-a, --about Shows Guake's about info
-n NEW_TAB, --new-tab=NEW_TAB
Add a new tab
-s SELECT_TAB, --select-tab=SELECT_TAB
Select a tab
-g, --selected-tab Return the selectd tab index.
-e COMMAND, --execute-command=COMMAND
Execute an arbitrary command in the selected tab.
-r RENAME_TAB, --rename-tab=RENAME_TAB
Rename the selected tab.
-q, --quit Says to Guake go away =(
And here is my shell script:
#!/bin/sh
# guakeStartup.sh
# open tabs
guake -e "irssi" -r "irssi"
guake -n -e "cd" -r "terminal"

Try it like this inside your startup script:
guake --rename-tab="irssi" --execute-command="irssi" &
sleep 1 &&
guake --new-tab=2 --rename-tab="terminal" --execute-command="cd" &
Or more like your original:
guake -e "irssi" -r "irssi" &
sleep 1 &&
guake -n=2 -e "cd" -r "terminal" &

Related

How to run command in last focused terminal window using bash?

How can I modify this function to open a new tab in the last focused terminal window, vs opening an entirely new terminal window?
# Opens a new terminal tab and runs the file.
run_in_terminal(){
# $1=file_path
msg="Running $1
in $qube_name Terminal..."
# notify-send "$msg";echo "$msg"
echo "$msg"
sudo gnome-terminal --tab --active --geometry=120X60 \
--title="$1" --working-directory="$code_directory" \
-- bash -c "$1; exec bash"
}

How to run .bash file in Mac?

I want to execute
Path : "/Users/Trans/Downloads/solr-6.1.0"
Command: "bin/solr start -p 8983"
and
Path : " /Users/Trans/Downloads/apache-activemq-5.12.0/bin"
Command: "./activemq console"
To make it executable on click I create one .command file
having
!#/bin/bash
"/Users/Trans/Downloads/solr-6.1.0" bin/solr start -p 8983
"/Users/Trans/Downloads/apache-activemq-5.12.0/bin" ./activemq console
Given chmode +x permissions to it
But something seems to be wrong, Code is not getting executed.
My aim is to create one batch/bash file on double clicking on it should open terminal and execute both commands or more than that.
Shebang begins with #! not !#
#!/bin/bash
# verbose mode ( or -v in shebang )
set -v
cd "/Users/Trans/Downloads/solr-6.1.0" && bin/solr start -p 8983
echo "press a key to continue"
read -n1
cd "/Users/Trans/Downloads/apache-activemq-5.12.0/bin" && ./activemq console
echo "press a key to continue"
read -n1

How to execute multiple commands after opening a new terminal tab

I need to open a new terminal tab and execute multiple commands on it, how can I do it. I have already tried the following,
gnome-terminal --tab -t "X" -e "cd ~/Desktop/terminal_test;mkdir test"
Here I need to cd into a new directory and create a new folder.
Try this:
gnome-terminal -x bash -c "cmd1; cmd2; …cmdN; exec bash"
You can use gnome-terminal. The script below will open 3 tabs running the respective commands..
tab="--tab"
cmd01="bash -c 'ls';'pwd';bash"
foo=""
foo+=($tab -e "$cmd01")
gnome-terminal "${foo[#]}"
exit 0

How do I get the command history in a screen session using Bash?

If I start a screen session with screen -dmS name, how would I access the command history of that screen session with a script?
Using the ↑, the last executed command appears, even in screen.
I use the default bash shell on my system and so might not work with other shells.
this is what I have in my ~/.screenrc file so that each new screen window gets its own command history:
Default Screen Windows With Own Command History
To open a set of default screen windows, each with their own command history file, you could add the following to the ~/.screenrc file:
screen -t "window 0" 0 bash -ic 'HISTFILE=~/.bash_history.${WINDOW} bash'
screen -t "window 1" 1 bash -ic 'HISTFILE=~/.bash_history.${WINDOW} bash'
screen -t "window 2" bash -ic 'HISTFILE=~/.bash_history.${WINDOW} bash'
Ensure New Windows Get Their Own Command History
The default screen settings mean that you create a new window using Ctrl+a c or Ctrl+a Ctrl+c. However, with just the above in your ~/.screenrc file, these will use the default ~/.bash_history file. To fix this, we will overwrite the key bindings for creating new windows. Add this to your ~/.screenrc file:
bind c screen bash -ic 'HISTFILE=~/.bash_history.${WINDOW} bash'
bind ^C screen bash -ic 'HISTFILE=~/.bash_history.${WINDOW} bash'
Now whenever you create a new screen window, it's actually launching a bash shell, setting the HISTFILE environmental variable to something that includes the current screen window's number ($WINDOW).
Command history files will be shared between screen sessions with the same window numbers.
Write Commands to $HISTFILE on Execution
As is normal bash behavior, the history is only written to the $HISTFILE file by upon exiting the shell/screen window. However, if you want commands to be written to the history files after the command is executed, and thus available immediately to other screen sessions with the same window number, you could add something like this to your ~/.bashrc file:
export PROMPT_COMMAND="history -a; history -c; history -r; ${PROMPT_COMMAND}"
screen doesn't maintain a history of the commands you type. Your shell may or may not keep a history. Since you appear to use bash, you can use the history command.
screen does appear to have a crude approximation of a history search (it merely searches the scrollback buffer for a command line. See the screen man page under the "history" command (bound to C-a { by default).
#technosaurus is right. $HISTFILE is written when bash exits, so you could exit one bash session, and start a new one, and the history should have been preserved through the file.
But I think there is a better way to solve your problem. The bash manual includes a description of the history built-in command. It allows you to save this history with history -w [filename] and read the history with history -r [filename]. If you don't provide a filename, it will use $HISTFILE.
So I would propose that you save the history inside your screen session to a specific file (or to your default $HISTFILE if you want). Then read the history file in the other bash session you want to access the history from. This way you don't have to exit the original bash session.
When you exit a terminal (or shell) the shell writes its history to $HISTFILE, so to get its history in another terminal you can type exit in the terminal you want the history of and it will get written.
cat $HISTFILE
#or tac, less, $EDITOR, ... depending on how you want to "access" it
use this:
screen -L
with capital L
it will store a copy of terminal input and output to a file named screenlog.0
or if you use -S to name it, the log file gets the screen name
I put the next lines into my .bashrc:
case "$TERM" in
screen)
declare SCREEN_NAME=$(echo $STY | sed -nr 's/[^.]*\.(.*)/\1/p')
if [[ $SCREEN_NAME ]]; then
HISTFILE="${HISTFILE}.${SCREEN_NAME}.${WINDOW}"
declare -p HISTFILE
fi
unset SCREEN_NAME
;;
*)
;;
esac
My default .bashrc has this 'case' basically with 'xterm*|rxvt*)' value, so I only added my 'screen' part into it. If you have not this 'case', you can use the next instead of it:
if [[ $TERM == screen ]]; then
declare SCREEN_NAME=$(echo $STY | sed -nr 's/[^.]*\.(.*)/\1/p')
if [[ $SCREEN_NAME ]]; then
HISTFILE="${HISTFILE}.${SCREEN_NAME}.${WINDOW}"
declare -p HISTFILE
fi
unset SCREEN_NAME
fi
And after I have an own bash_history for all window of my all screen.
Note: this not work in chroot!
history will show all the history command.

exo-open in a terminal script - program closes with the terminal

I've written a simple bash script that prompts for a file or directory path and opens it with exo-open, I've then assigned the script to a keyboard shortcut so that I can CTRL+SHIFT+ALT+O to open anything at anytime via a terminal prompt:
And the script:
#!/bin/bash
# CD to the home folder (not sure if this is needed, no harm either way)
cd ~/
# Request the filepath
echo -e "\e[1;31mEnter a file or directory:\e[00m"
read -e -i "~/" filename
# Convert ~/ to /home/username/
filename=`eval "echo $filename"`
echo -e "opening\e[1;32m" $filename "\e[00m"
# Open the file
exo-open "$filename"
echo "press enter to exit"
read enter
My problem is that the spawned program is linked to the terminal, when the terminal closes it takes the program with it - as a simple workaround I have another user prompt at the end to stop the terminal from closing; does anyone know how I could allow the terminal to close but keep the resulting program open?
Some ideas I've had / tried:
run disown $! after exo-open (didn't work)
use nohup (didn't work)
Run exo-open from the PPID (no idea how to do this)
At my wits end :-(
I had this answered by Xfce forum member ToC
http://forum.xfce.org/viewtopic.php?pid=25670
Turns out you can use setsid like so:
#!/bin/bash
# CD to the home folder (not sure if this is needed, no harm either way)
cd ~/
# Request the filepath
echo -e "\e[1;31mEnter a file or directory:\e[00m"
read -e -i "~/" filename
# Convert ~/ to /home/username/
filename=`eval "echo $filename"`
echo -e "opening\e[1;32m" $filename "\e[00m"
# Open the file
setsid exo-open "$filename"

Resources