C on GNU/Linux, replace terminal strings - linux

Actually when i open the terminal i got this default string:
username#hostname:~
I want to replace the above string whit this one:
<myprgrogram>:~
How can i do this?
I'm developing in C on GNU/Linux).
Thanks in advance!

You need to set up your prompt as detailed here (I'm assuming you're using bash).
There are numerous options and capabilities. See here for a gallery of examples.

If you mean current path, then add the below line to your .bashrc file.
export PS1='<$PWD>:'

You can change an environmental variable using setenv/putenv from the standard library (stdlib.h), see "man setenv".
However, when the program ends the variable won't be saved.

Related

Understanding a Linux Command Syntax that Fixed LibreOffice

Greetings and pardon the lengthy title,
To preface: I solved an issue where after downloading LibreOffice, the splash screen would show up, but nothing would happen afterwards
Below is the solution that fixed my issue:
Step 1. SAL_DISABLE_OPENCL=1 soffice
Step 2. libre office should open - open Tools -> Options -> LibreOffice -> OpenCL and disable the option "Allow use of OpenCL"
That being said, I'm trying to understand what happened in step 1. It appears to me that we are opening a subshell via the soffice command with the variable SAL_DISABLE_OPENCL changed in the context of said subshell
I've never seen or read about this before, and gave up trying to google the correct string of words. Does this concept have a name? I tried soffice --help but there is nothing to indicate this syntax
Any help is greatly appreciated, thanks!
Running SAL_DISABLE_OPENCL=1 soffice runs the program soffice passing to it the environment variable SAL_DISABLE_OPENCL set to the value 1. It does not run a subshell, it is run on your current shell. This syntax is described in the bash manual:
The environment for any simple command or function may be augmented temporarily by prefixing it with parameter assignments, as described in Shell Parameters. These assignment statements affect only the environment seen by that command.
That environment variable is a value treated specially by LibreOffice to force that option to be disabled.

what is the meaning of shell title?

I'm new to linux. And I'm confused with the different shell titles in linux.
for example, when I called "/bin/sh", I saw
sh-3.1#
but when I used "su root", I saw
my-environment:~#
and when I logged in as normal user, I saw
user#my-environment:$
I kind of notice # means root and $ means non-root, but could some explain how I got the above titles?
Thanks a lot!
The text at the shell prompt is controlled by the variable $PS1 (and sometimes $PS2 $PS3 $PS4). This blogpost explains how you can customize the prompt in many ways.
Do echo $PS1 in the different terminals to see the current value.
This depends on your variable environment $PS1.
To see what I mean, try doing PS1=something, and see what happens.
To reset it you could do source ~/.bashrc.
So, why do you have different prompt according? Because you don't load the same files according to the command you type to open your sessions, so you end up with different configs, hence a different $PS1

Find: Parameter format not correct

I keep hearing this is a path issue with cygwin. It is prevent emacs from working within my cygwin. When I execute find on the cli (not bash/cygwin) I get the same error not matter what I type. I've read this is a problem with path creation within cygwin and that it should be prepending itself to the path. As you can see it is doing that.
Here is my /etc/profile
PATH=/usr/local/bin:/usr/bin:/bin:$PATH
export PATH
Problem is that as everyone else stated, emacs is using find.exe provided by windows. To change this, you need to change your %userprofile%.emacs file.
As nobody else states (even faq!), this file is not created automatically anymore. Go into Options > Save options the mini-buffer (one line at the bottom of emacs) will tell you where the file is being written to.
Go in there and add this line (You've installed cygwin at c:\cygwin, right?):
(setq find-program "C:\\cygwin\\bin\\find.exe")
You may need to restart Emacs for this to take effect.
Just add this line to you .profile
alias find='/cygdrive/c/cygwin/bin/find.exe'
Oddly-enough, I needed to use
(setq find-program "/bin/find.exe")
instead.
But thanks for the suggestion Drew.
Adding a setq find-program [msys2 or git path] in my init file, as suggested (I tried different forms), didn't work for me. "C:\Windows\System32\find.exe" is first in the path if I type where find in eshell and I didn't find how to remove it, only how to add others, which doesn't solve the problem.
So I share here the more radical, but working (also in Powershell), solution I used: replacing the find.exe in "C:\Windows\System32" with the one from "C:\msys64\usr\bin". I kept the old file in case, but so far so good. You need to change the permissions for this operation (see here how to gain full control, but I suggest only applying this to the file, not the whole folder, and putting things back after ;)).

Make a Linux "GUI" in the command line

How to make a Linux program in the Command Line Interface who display a nice user interface?
For example when I use "wget" to download a file from internet, I can see the download advancement in the Command Line Interface. How can I do that?
ncurses is a popular option, there are APIs for lots of programming languages.
Take a look at curses. It is a library for text based UI.
You can get a basic interface by using \r to go to the beginning of the current line.
Slightly more advanced is ncurses.
The next step up is Newt.
If you want to do a GUI for Bash scripts or to wrap around other command line utilities, you can use dialog (man page).
Here two great dialog tutorial to get you started :
Dialog: An Introductory Tutorial
Improve Bash Shell Scripts Using Dialog.
If you only need a progress bar, this can be done directly with a simple print (that prints the bar), followed by the carriage return character (ANSI character #13), which puts you back at the beginning of the line. The line can then be later updated by printing over it.
For more complicated needs, ncurses is indeed the standard way to go.
I wouldn't call wget's progress report as a 'nice gui', but anyway, the classic library for building graphical interfaces without X Windows is Linux and UNIX systems is ncurses.
Recently a C# version of ncurses has been started, check out details here
If you're using Mono, you could use MonoCurses
Try curses, it is a well documented API for text based UI.Also, there is so much open source projects that are using curses for you see and learn
wget does not really have a GUI, all I see is stuff that you can already achieve using stdout and echos (e.g. printf() or std::cout)
Anyways, for simple dialog boxes of the MessageBox kind, but not limited to that, also have a look at dialog
http://linux.die.net/man/1/dialog
http://hightek.org/dialog/
You can just use ANSI escape codes. A simple example in bash
echo -e "\033[H\033[2J \033[20;20H \033[4mThis is a underlined line.\033[0m"
One should mention FTXUI. Functional Terminal (X) User interface: A simple C++ library for terminal-based user interfaces!
Cross-Platform
Support for UTF8 and fullwidth chars (→ 测试)
No dependencies
etc

How do the Server Extensions work in X?

Let's take an example. When I run:
xkbprint $DISPLAY keyboard.ps
what happens in the system? I would like to know how the X really work because I regularly get nasty error reports such as
Fatal Error: Cannot load geometry for /tmp/launch-NawGIk/:0
Exiting
I know that the X11 was designed in a way that it is easy to extend. But how? How does the X11 protocol work? How do the X extensions work?
Whatever happens, I'm pretty certain it isn't going to be what you expect.
The syntax of xkbprint(1) is
$ xkbprint sourcefile destfile
and sourcefile should be a compiled xkb file. $DISPLAY is going to resolve to something like mymachine:0.0, which isn't a very reasonable file name.
Actually, since you're running a Mac, it's echoing exactly what it's seeing: /tmp/launch-NawGIk/:0 is the special OS/X magic to let launchd run X apps. The error message means that it's not finding a geometry or display in that file. Which is no surprise since there is no file named `/tmp/launch-NawGIk/:0
Try reading the man page, and see if you don't have more luck with a compiled .xkm file.
More generally, if you want a starting introduction to X, try this article.
Man xkbprint says:
The xkbprint comman generates a
printable or encapsulated PostScript
description of the XKB keyboard
description specified by source. The
source can be any compiled keymap
(.xkm) file that includes a geometry
description or an X display
specification.
As Charlie Martin pointed out, xkbprint is misusing your $DISPLAY as a file name. Try specifying the display more precisely, to avoid ambiguity with file name. Try man xhost. Maybe passing simple ":0" will fix the problem?

Resources