How do you get a launcher for firefox? - linux

I hope that I'm tagging/asking on the correct page. I'm Using Linux Mint 6.0, but it could be OS independent.
So the used command for installing Firefox was
nix-env -iA nixpkgs.firefox-esr
When I type which firefox, I get:
/home/foo/.nix-profile/bin/firefox
So Linux Mint comes with Chrome preinstalled, which has a launcher, e.g. also in the start menu. How do I get that for firefox as well? I didn't find a tool to create such a launcher in Mint and I actually think, that nix should do that for me.
EDIT: I also found this page which seemed helpful and advertised e.g. the KDE Kickoff, but I wasn't able to get that one to run.

I can only speak for Ubuntu launchers, but other distros will have launcher files that will have a similar setup
TLDR, add ~/.nix-profile/share to XDG_DATA_DIRS env variable on login. Add the following to ~/.profile after nix loading commands
export XDG_DATA_DIRS=$HOME/.nix-profile/share:$XDG_DATA_DIRS
Explanation:
Installed packages via nix will have an immutable path in nix/store. ~/.nix-profile/bin/firefox is the derivation your current nix environment is linked to (if you update the firefox package, it'll point to the new one)
This means you can create a launcher file for that executable. Lets see if the firefox-esr derivation comes with a desktop launcher or not:
$ nix-build '<nixpkgs>' -A firefox-esr
This will build the package and give you a derivation path. For my current channel it is /nix/store/3iipcmiykgr4p34fg3rkicdz1bw584gm-firefox-102.2.0esr
If I check inside it, there is a .desktop file which defines Ubuntu launchers:
$ ls /nix/store/3iipcmiykgr4p34fg3rkicdz1bw584gm-firefox-102.2.0esr/share/applications
firefox.desktop
These files will also be available under ~/.nix-profile/share/applications so you can simply add that to XDG_DATA_DIRS env variable before boot
If an application did not have one, you can manually make one and add it under ~/.local/share/applications, then set the executable path to the nix one

So SuperSandro2000 explained in the comments, that firefox from nix ships with a .desktop file already. This can be easily added to the start menu and lies in
/nix/store/...-firefox-XXX.X/share/applications/firefox.desktop
If there is no such file included, the most direct way could be (imho) to just create a simple bash script:
#!/bin/bash
./home/foo/.nix-profile/bin/firefox & #Run Firefox
echo Firefox was started with PID $!
In order to make it runnable, enter chmod +x your_skript_name.sh. Afterwards, ./firefox 2> /dev/null & can be used instead to run it silently in the background.
You can also consider the developer/command line options for firefox (Archive) or this blog article here.
Maybe /usr/bin/menulibre is also the right application, it allows you to create .desktop files. This app can also be found by right-clicking on the start "menu".

Related

WSL2 distro shell can't launch a file copied from outside

The situation in short
I can't launch an executable (binary or a script) in a WSL2 distro if it wasn't created inside this distro
I can launch scripts and binaries that were created inside the distro shell (not using /mnt/c or /mnt/d in any way)
But I can't launch anything that was created outside and copied inside from Windows (using /mnt/c or /mnt/d)
I can see the copied files in the file system, can "cat" them, can look them up with "which", but I cannot launch them by entering the path into the command line
The questions I have in regards to all this
How come that the shell can't see the files while utils you run from the shell can?
How do I make the shell see files that were copied from outside?
If I can't make the shell launch the files, then how do I launch them?
The Situation in detail
I have Windows 10 with WSL2 and two distros
Ubuntu-20.04
Alpine
In Ubuntu I have a "Hello, World!" project written in C
It compiles in Ubuntu and then and runs in Ubuntu just fine
But, when I copy it from Ubuntu to Windows
cp hello /mnt/d/
and then go to Alpine and copy it inside from Windows
cp /mnt/d/hello .
I then have trouble launching it inside Alpine
Here is the output of file hello command in Ubuntu with some extra formatting (just in case)
$ file hello
hello:
ELF 64-bit LSB shared object,
x86-64,
version 1 (SYSV),
dynamically linked,
interpreter /lib64/ld-linux-x86-64.so.2,
BuildID[sha1]=021352ab7bf244e340c3c42ce34225b74baa6618,
for GNU/Linux 3.2.0,
not stripped
Here's what I have in Alpine
$ cp /mnt/d/hello .
$ ls -l
-rwxr-xr-x 1 pavel pavel 16760 Apr 19 19:07 hello
$ ./hello
-ash: ./hello: not found
Now same with a script copied from Windows
Copy the script inside Alpine from Windows
$ cp /mnt/d/hello.sh .
Checking the contents
$ cat hello.sh
#!/bin/ash
echo Hello!
Setting the execute permission just in case
$ chmod agu+x hello.sh
Trying to run it
$ ./hello.sh
-ash: ./hello.sh: not found
But, I can launch the hello.sh by explicitly calling the ash tool and passing the script path as the argument
$ ash ./hello.sh
Hello!
At the same time, a script created inside Alpine runs just by entering it's path to the command line
$ cat << EOF > hello-local.sh
> #!/bin/ash
> echo Local hello!
> EOF
$ chmod agu+x hello-local.sh
$ ./hello-local.sh
Local hello!
Also, I couldn't make a file that would run from one that wouldn't either by copying it with cp
cp hello.sh hello2.sh
or by copying it with cat
cat hello.sh > hello3.sh
cmod agu+x hello3.sh
Why do I need to copy things from outside
It all started when I wanted to explore how Docker for Windows uses Linux namespaces to separate containers
The distro that Docker for Windows uses is called docker-desktop
The docker-desktop distro neither has utilities that I need for my experiments, nor a package manager to get those utilities
So I tried to copy them from outside
But now Docker for Windows studies is not the only concern
I want to understand this magic that is happening just as bad
To be fair, there really are three separate questions here, but not necessarily the questions you listed in your post:
Secondary question -- Why does your script that you copied to Alpine fail?
As #MarkPlotnick covered in the comments (and you confirmed), it was due to the script having DOS/Windows line endings (CRLF). In general, try to avoid creating or editing Linux text files using Windows tools unless you are sure that they are using Linux line-endings.
Secondary question -- Why does your C program fail when you compile on Ubuntu and copy the binary to Alpine?
Also as #MarkPlotnick mentioned in the comments, this is because Ubuntu uses glibc as the standard library implementation by default, but Alpine uses musl. See a number of questions here for more information. The first one in the list sorted by "relevance" is actually a pretty good one to start with.
Main question -- How to explore the docker-desktop distro
Really, your main goal seems to be how to gain access to certain tools inside the docker-desktop distro in order to learn more about it.
I was going to say, "don't" (with more explanation), but the reality is that I think it's a potentially good learning experience. I've done it, to some degree, so who am I to say it's "too dangerous" or recommend against it? ;-)
I will give fair warning, though -- The docker-desktop distro isn't intended to be run by users. Docker Desktop "injects" links and sockets into your other WSL2 distros (which you can enable/disable per-distro in Docker Desktop) so that its tools, processes, etc., are available to all your WSL2 (and PowerShell/CMD) instances.
I'd personally try to avoid making any changes to the docker-desktop distro itself. They'll likely be overwritten anyway by Docker Desktop when it extracts a new rootfs.
However, we can still gain access to the tools we need by accessing them from another distribution, but without copying them into docker-desktop.
First, a note -- As I think you have probably already figured out,docker-desktop is also musl-basesd. So you'll want to use tools from another musl-based distro like Alpine.
This can be easily accomplished by running the following line once in your Alpine instance (as root):
echo "/ /mnt/wsl/instances/Alpine none defaults,bind,X-mount.mkdir 0 0" >> /etc/fstab
That will add a mount to the Alpine instance into the tmpfs /mnt/wsl mount. You can see my Super User answer here for more details on that.
Once you wsl --terminate Alpine and restart it, you'll have access to the Alpine files from any other WSL2 distribution.
As a useful (for your intent) example, install the util-linux package in Alpine to get access to the lsns command.
Then, in the docker-desktop distro (which I assume you already know to access with wsl -u root -d docker-desktop, but I'll include that command here for other future readers), to list the namespaces:
/mnt/host/wsl/instances/Alpine/usr/bin/lsns
The docker-desktop instance automounts at a slightly different directory than default (see cat /etc/wsl.conf), so you need to adjust the path to /mnt/host/wsl instead of /mnt/wsl.
But with that in place, you can run all (most?) of your Alpine binaries directly in docker-desktop without having to modify it directly. If you have a script in your home directory that you want to run in docker-desktop, for instance:
/mnt/host/wsl/instances/Alpine/home/users/<yourusername>/hello.sh
Note that if you have a binary that requires a dynamically-linked library on Alpine, I'm assuming you'll need to adjust your LD_LIBRARY_PATH accordingly, although I haven't tested. For instance:
LD_LIBRARY_PATH=/mnt/host/wsl/instances/Alpine/usr/lib /mnt/host/wsl/intances/Alpine/usr/bin/<whatever>

How to stop the Cygwin terminal from forgetting the environment when opening it in a non-home folder?

I got Ocaml for Windows which comes prepackaged with Cygwin. Since I wanted to be able to open mintty from the command line in the current directory, so I added it to PATH and then just running mintty does the trick. While this causes it to open in the current directory the problem is that when I run any of the Ocaml executables like opam I get an error.
Marko#Lain /cygdrive/e/Webdev/Ocaml/todolist
$ opam
bash: opam: command not found
When I run it using mintty - like the shortcut does, this in fact works.
Marko#Lain ~
$ cd "E:\Webdev\Ocaml\todolist"
Marko#Lain /cygdrive/e/Webdev/Ocaml/todolist
$ opam
usage: opam [--version]
[--help]
<command> [<args>]
The most commonly used opam commands are:
init Initialize opam state, or set init options.
list Display the list of available packages.
show Display information about specific packages.
install Install a list of packages.
remove Remove a list of packages.
update Update the list of available packages.
upgrade Upgrade the installed package to latest version.
config Display configuration options for packages.
repository Manage opam repositories.
switch Manage multiple installation prefixes.
pin Pin a given package to a specific version or source.
admin Tools for repository administrators
See 'opam help <command>' for more information on a specific command.
What do I have to do so that I get this behavior normally?
Also, since mintty runs a terminal in a standalone window, it would be better to run bash, but bash - does not work for me. After I get this to work, I'd like to add bash to my list of VS Code shells and for that I'd need to understand how to run it in an arbitrary directory from the command line while keeping its memory of the home environment.
This command mintty - start your shell as login one.
If you run a not-login shell, most of the configuration script are not read, and enviroment is taken from the father process, but of course your link fails as Windows can not provide a proper one.
If you want to be able to open a login shell from explorer the best way is to install chere package
$ chere -h
/usr/bin/chere version 1.4
Usage:
/usr/bin/chere -<iuxlrhv> [-lracnmpf12] [-t <term>] [-s <shell>]
[-d <display> ] [-o <options>] [-e <menutext>]
Adds the stated terminal/shell combination to the folder context menu
This allows you to right click a folder in Windows Explorer and open
a Cygwin shell in that folder.
Options:
i - Install
u - Uninstall
x - Freshen eXisting entries
l - List currently installed chere items
r - Read all chere registry entries to stdout
a - All users
c - Current user only
n - Be Nice and provide Control Panel uninstall option (Default)
m - Minimal, no Control Panel uninstall
p - Print regtool commands to stdout rather than running them
f - Force write (overwrite existing, ignore missing files)
1 - Start using registry one-liners. This doesn't work with ash,
tcsh or network shares.
2 - Start via bash script. Relies on windows to change directory,
and login scripts avoiding doing a cd /home/Marco
h - Help
v - Version
t <term> - Use terminal term. Supported terminals are:
cmd rxvt mintty xterm urxvt
s <shell> - Use the named shell. Supported shells are:
ash bash cmd dash fish mksh pdksh posh tcsh zsh passwd
d <display> - DISPLAY to use (xterm, urxvt). Defaults to :0.
Set to env to use the runtime environment variable.
o <options> - Add <options> to the terminal startup command.
If more than one option is specified, they should all be
contained within a single set of quotes.
e <menutext> - Use <menutext> as the context menu text.
See the man page for more detail.
You can than install your preferred or default shell on explorer right click menu as an additional item. It will open a login shell in the chosen directory.

how to run non-installed(portable) application using linux terminal

I'm new to Linux and i use Kali Linux. I downloaded the eclipse ide. Every time, when i need to run it, i should navigate to eclipse folder and run the eclipse file. there are other softwares like pycharm have the same issue.
If there's any method to run these programs just typing "eclipse" or "pycharm" on terminal (like firefox, atom) it's very helpful. If anyone know how to do it please let me know. I already searched a solution for this problem and i couldn't find any solution.
-Thanks (sorry for my English)
Modify your ~/.bashrc and add the PATH of your application(you use PATH rather then CONFIG_PATH)
export PATH=$PATH:/path/to_directory_containing_program
export CONFIG_PATH=/my_path_to_PROGRAM/PROGRAM/config/
Another solution is Create a shorcut in your desktop
Go to cd /usr/local/bin (or cd /usr/bin) and do:
sudo ln -s /path/to/eclipse where eclipse is the binary that you are used to launch.
/usr/local/bin and /usr/bin directories should already be in your PATH, so you don't need to modify ~/.bashrc.

Package installed by Nix not in Mate desktop menu

I have used Nix package manager to install Abiword in a Slackware/Salix install with Mate desktop. The application runs fine but it has not appeared in the main Menu. Is this usual for applications installed by Nix?
I got this working on openSUSE plasma-desktop by adding the following to my bashrc
export XDG_DATA_DIRS=~/.local/share/:~/.nix-profile/share:/usr/share
cp -f ~/.nix-profile/share/applications/*.desktop ~/.local/share/applications/
Then logging out or running kbuildsycoca4 rebuilds the start menu.
When I only set the XDG_DATA_DIRS, the icons would appear in the start menu. However kdelibs is trying to make those .desktop files executable and add a xdg-open shebang to them, which does not work since .nix-profile is not writeable.
Thus it was also necessary to copy the desktop files to a ~/.local/share/applications/, which however also needs the XDG_DATA_DIRS set to ~/.nix-profile, because the application icons still reside there.

run jedit single command from terminal linux

I'm trying to run jedit from the terminal on fedora. its installed to the path /usr/local/share....
How do I get it to run "jedit" from the terminal rather than switching to the directory and typing java -jar jedit.jar to execute the program.
I created a sh file in that same direectory with "java -jar jedit.jar" and added that directory to ~/.bashrc. I'm aware that I need to type "sh file.sh" to run that file but I know there is a gap in my knowledge somewhere.
i want to use jedit as a commit editor for git and be able to change core.editor='jedit -w' in git config
someone please help
I assume you used the Java installer?
If this is the case, the installer should also have placed a jedit launch script in /usr/local/bin which should be in your PATH by default, so calling jedit from a terminal should instantly work after installation.
If it does not work, then please check whether the file jedit is available in /usr/local/bin and whether /usr/local/bin is in your PATH environment variable.

Resources