Run a Command When Terminal Opens (Linux) - linux

This feels like a stupid question, but I can't find an answer (that works) anywhere. So, I thought I'd ask it here.
Basically, I would like a command to run every time I open a Terminal window, and then show the output in the Terminal (I have Fedora). Is this possible with the MOTD, or is that text-only?
Thanks!

Put it in ~/.bashrc or equivalent.

Related

How do you properly use a .desktop icon to launch a python3.8 Tkinter GUI on Ubuntu 18.04?

Premise: I coded a Tkinter GUI for a python script. It works. I can launch it from terminal. I created an icon and the icon will show up in my GUI just fine. I've been looking for tutorial on .desktop launchers and none of the examples I've found work. After a few hours of wading through SEO spam in SERPs trying to find a tutorial on the subject or a forum question that has been correctly answered. Finally I decided to join a forum ask a question. I've found a lot of code snippets on this site in the past. Figured I would try here.
I've tried about 20 different examples none of which have worked but I think I at least know the questions to ask. Here's an example of a .desktop file: It's not an example that works but it's one on found on this site so I figure I will start there.
[Desktop Entry]
Type=Application
Terminal=false
Icon=/path/to/icon/icon.ico
Name=ApplicationName
Exec=python3 /path/to/application.py
Categories=Application;
Note the example in the other post shows a red highlight over Categories=Utility; and when I try to change it in /usr/share/applications/ it makes gnome-terminal insert an A when hit the up key to get my last BASH entry and change a bunch of keys on my keyboard into hotkeys rather than being able to type it pops open print dialogs and things like that that which is wicked annoying.
Does anyone want to discuss what each entry line in a .desktop file is supposed to look like. Also does the application, icon, and everything have to be in /usr/share/applications? What file locations are ok to use in this type of file?
Something else I thought of; is it possible that my Exec line is not correct. Does exec have to be a single argument? Do I need to create a bash script that can be called by Exec that is just something like ./script.sh or should I create a command alias that is a single argument? Or does it actually matter?
I also have a Linux question: What package handles .desktop icons? Who maintains said package? And where can I find actual documentation on the subject?

Bash Console commands (Codeship console): how to exit from current "inputs"

Excuse me for the imprecisions in the question but I don't know how it is called what I'm trying.
In the CodeShip documentation is stated that I can pass to the SSH CodeShip debug build some commands using their command line application.
So, I should do something like cs setup-commands and I'm prompted with this:
rof#railsonfire_unique_string_sfivbe8bwucb9:~$ cs setup-commands
Your setup commands:
phpenv local 5.6
phpenv local 5.6
In Your setup commands: I put my commands but then, how can I "execute" them?
The second phpenv local 5.6 line is wrote by the command-line application. I think is something to signal the command were taken, but the behavior is ever the same: I remain "blocked" in the command setup-commands. After setting setup-commands I have to set also test-commands but all the things I write are taken by Your setup commands:.
How can I "submit and exit" the command setup-commands to then launch test-commands and set those other commands?
I think this is something related to Bash, but I don't know what it is...
And I don't know which is the correct terminology.
Can someone help me with this? So I will can also update my question to be more precise. Thank you.
Not sure about your case, but usually the input is considered finished, when th input file (in your case stdin) is closed.
Try to press Ctrl+D, it should end your input (and so signal the program hat you stopped typing for this session)

How to automatically open prompts, ssh, and do things using a script?

I have to connect to a linux server from my own Ubuntu machine and operate directly on the server.
A dozen of folder names are listed in a LIST file. How to write sth. (like a bash script?) to carry out the following procedures?
for fold_name in LIST {
/******on my own Ubuntu*******/
-- open 2 new tabs of prompt terminal
-- run an ssh command in both
-- then input passwd and log in automatically in both
/******on the linux server*******/
-- cd to directory xxx/fold_name in both
-- run aaa.exe in 1st tab
-- vim sth in the 2nd tab
}
Once the loop of open-tab-login is solved, I guess the second part is routine as simple bash script except that I don't know how to specify between 2 tabs, either.
The point is I want all tabs in the same terminal. To this end, manually, I often Ctrl+Alt+T to create a prompt and Ctrl+Shift+T to open many tabs within it. And ssh...cd...... in each one. You see how annoying and cumbersome it is!
There are a few things you might like to research, which will get you a little closer.
You can run an ssh without a password, if you use an ssh key. Check out ssh-keygen, and the -i option in ssh.
Opening up tabs in gnome-terminal can be done via the method described here: Open a new tab in gnome-terminal using command line
You can run specific commands (e.g. aaa.exe) on a remote box over ssh, by including the command after the ssh: ssh user#remotehost aaa.exe.
If you want multiple commands, try enclosing them in quotes: ssh user#remotehost "cd /xxx; aaa.exe". Vim does not need to be in the directory in question in most cases: ssh user#remotehost vim /xxx/filename"
If you want to do something interactive (like vim), include the -t flag in ssh.
The tabs will be independent of each other - I'd probably run half of the command in one window, the other (e.g. runnning aaa.exe in one window, using one command, and the vim in another window, using another command, that I just happen to run at the same time. This way I can resize the windows, and arrange them relative to each other, and see both at once.
-- open 2 new tabs of prompt terminal
This depends on which desktop you're using. For gnome, gnome-terminal takes the -e option to specify the script to execute in the new terminal window. So, for something like this, you would execute gnome-terminal -e $script &, placing each instance of gnome-terminal in the background.
If you're using a different desktop, other terminal applications typically have a similar option. So, you'd point the terminal application to a script that's going to run in the terminal, and complete the rest of your task for you.
-- run an ssh command in both
-- then input passwd and log in automatically in both
This is going to be more complicated. The classical solution is the expect utility. There might be other similar tools that do similar things, but expect is pretty much the usual way these kinds of things have been done in the past. When it comes to trying to automate an interactive application, expect is really the only way to go. Unfortunately, expect uses a somewhat arkane syntax, that first-time users typically find confusing, and hard to understand. I grumble, every time I see no other alternative but to use expect to automate something, but this is pretty much the only option that's usually available.

Node command line interface change

I'm making a command interface for a node server, but I have reached a point that I want it to look better.
I want to have the console so you enter a command at the bottom of the terminal screen, you hit enter, and it adds the reply to the actual command line.
If you have ever run a minecraft bukkit server from the command line, you should know what I'm talking about.
Here's a picture of what I'm talking about if you still don't understand. Imagine this was in terminal, and ignore the scroll bars: http://cl.ly/1K0h1V0r0H3f3U3t3L22
Is there anyway to set the console to look like this without having to make your own program for it or having the screen reprint all the other info to fake that look?
I have not done this, but I believe something similar is possible with very little effort by using Node.js REPL. You can override the eval parameter to provide your own command processing.
It would not have the exact look you are wanting, but it will be an interactive prompt that you can utilize (more similar to a Windows command shell or a Linux shell).
If you want the exact look from your screenshot, I don't believe that there is any Node.js module that will help you. There are some that allow you to use colors in the console, and some basic highlighting (e.g. bold), but nothing that gives you complete control over the console screen.

Emacs... as your default shell?

Is it possible instead of loading /bin/bash, for my terminal to load emacs or emacsclient when I open it up, with a session for eshell? And is it feasible to ssh->screen from an emacs session without running into problems?
I want to do this purely to learn about emacs being as I like it so much.
No hate text, etc please :)
emacs -f eshell
EDIT:
If you don't want to start a new emacs you can use emacsclient.
emacsclient -e '(eshell)'
Make sure you have started the server the best way to do it is to add
(server-start) in your . emacs
You can set your shell to /usr/bin/emacs (or wherever it is) to make it your default shell. It will probably act weird though since Emacs is not a shell. It's an editor. Programs expect your shell to behave in a certain fashion and Emacs won't work that way.
You can do an M-xtermret to get a terminal from which you can connect to a remote machine and start a screen. I don't know about the quality of the emulation though. No harm trying.
Neither of these look useful to me and the former is definitely a trouble maker.
Yes you can. I did for a few months once. A few things act funny most can be tamed. It was a great laugh to see coworkers react when they saw me log in to emacs.
Just tried running screen from within Emacs (in a shell buffer), but I get the following:
angelv#vaso:~$ screen -D -R
Clear screen capability required.
angelv#vaso:~$
so I guess that's not possible. In any case, I don't see why you'd want this (and I use daily screen + emacs).
echo /usr/bin/emacs >> /etc/shells
chsh -s /usr/bin/emacs

Resources