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

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.

Related

How do you get a launcher for firefox?

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".

nvim started as desktop application | :checkhealth - commands not available

When I start neovide from my applications and run :checkhealth I get errors that node and other commands are not available. But when I start it from my terminal there is no error for those commands. I tried to copy and modify the neovide desktop file to start just nvim and see if there if something wrong with my my neovide installation. But also starting just nvim as application prints the same errors.
I'm using linux with plasma desktop
TL:DR; add a path variable
Depending on your configuration, nvim will need to know the environment to run some executables (like it is with node in your example). An easy solution is to add the path variable to the exec command in the according .desktop file. I remember that I had the same issue with node not being recognized in a configuration using my plasma installation. On gnome node was recognized and healthchecks were good, so I thought I didn't need the extra path. Later on I realized that I had trouble with other commands. E.g. when using fdfind to complete path commands. Again I had to search what the reason was and it also was the missing path.
To give an example, let's say you are using zsh and want to start neovide with multigrid enabled, the Exec line in your desktop file could look like:
Exec=zsh -c "source ~/.config/zsh/.zshrc && neovide --multigrid %F"

dotnet-install.sh not adding dotnet command on Ubuntu

I am not a Linux user so this might be a easy fix but I have tried the following:
first I install it using the command curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin for which I get the following result:
dotnet-install: .NET Core SDK version 2.1.403 is already installed.
dotnet-install: Adding to current process PATH:
/home/<!username!>/.dotnet. Note: This change will be visible only when sourcing script.
dotnet-install: Installation finished successfully.
I do . ~/.profile to reload the profile,
but even after this when I run dotnet I get the following error:
Command 'dotnet' not found, but can be installed with:
sudo snap install dotnet-sdk`
I was expecting the script to do everything and make dotnet available.
TLDR: curl | bash can not modify PATH so it will not add dotnet to your PATH. You need to add dotnet to your path manually. Add export PATH="$PATH:/home/<!username!>/.dotnet" to your ~/.profile (or ~/.bashrc or equivalent) and log out and log back in.
Long version:
When you run a command in the shell (for example, bash), the shell tries to find an executible with the name in the all the paths listed in the environment variable PATH. PATH is generally set to something like /bin:/usr/bin. So when you type a command like curl, your shell looks in both /bin and /usr/bin for an executible file named curl.
You can see what your PATH is by doing env | grep PATH or echo $PATH.
The other important piece of information is how environment variables propagate. It's quite simple, actually:
A program (or process) can only modify its own set of environment variables.
Any child processes that a process creates inherit its environment variables.
What this means is that a program that you execute can not modify the environment variables of another random program. The shell actually provides a special command, export to set its own environment variables (and any child processes it later creates will inherit those).
Note the output at the end of step 1.
Note: This change will be visible only when sourcing script.
If you run curl | bash, it runs bash as a child process. That child process can not modify the environment variables of the program that started it (the shell that invoked curl | bash). So it can not modify PATH to add the location of dotnet to it. It even (helpfully) tells you that it can't.
In step 2, you are reloading ~/.profile. But does it contain any commands to add dotnet to PATH? I dont think so. I know the dotnet-install.sh script has not historically added it. You need to add a line like
export PATH="$PATH:/home/<!username!>/.dotnet"
To your ~/.profile (or ~/.bashrc, or equivalent) manually.
Actually, I would write it as follows to make the change more portable to other users:
export PATH="$PATH:$HOME/.dotnet"
Try running this again:
sudo add-apt-repository universe
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install dotnet-sdk-2.2

How to create files and folder in Atom using the command line?

I was watching a speedy workflow tutorial about Atom text editor, and saw how the guy uses Linu commands like ls (to check the files in the directory), touch (to create files eg. style.css) and mkdir (to create folders). Now in my Atom editor I am able to open the command line using the following command.
CTRL + SHIFT + T
Now in my command line the default windows command line opens up, I am able to create folder using mkdir, but the commands touch and ls don't work, which makes me wonder weather Atom has its own command line?
See the SCREENSHOT to see how this guy is creating folders, files and using the ls command.
So my question is, how do I create files in Atom? How do I get the touch command to work?
It looks like the tutorial is using the Term2 package for opening a shell within the editor (http://code.tutsplus.com/courses/speedy-workflows-with-atom/lessons/term2). Since you seem to be able to open a terminal using the described screenshot, you seem to have the Term2 package installed - so far so good.
This package opens a standard command window within the editor. The tutorial seems to be using Linux or Mac OS X as the operating system. If you're running Windows, you will only have the Windows CMD interpreter available.
Windows does not natively support the touch command (but it has a mkdir command). There is a unxtools project that provides some of the common Gnu tools. If you install that, you should be able to run touch from the Windows command shell as well. More details can be found here.

Subversion CLI default text editor on Linux

While there is no shortage of information on how to set a text editor for the Subversion Command Line Interface to use (see here, here, and here for example), I can't figure out where my local system is getting the text editor information from.
On my system, when I perform an svn commit, it opens vim for a commit message. Since this is what I want, I never really thought about it. This has always just worked. However, recently a co-worker was trying to commit, and it failed with an error saying the editor was not set. I never went out of my way to set an editor, so I am very confused about this.
I am running Ubuntu 12.04 and I have compiled and installed the Subversion CLI client version 1.8.10 from source code. Previous to that, I was using whatever Ubuntu's Canonical system installed with apt-get install subversion.
The Using External Editors section of the Subversion Book states the following possibilities for setting the text editor:
--editor-cmd command-line option
SVN_EDITOR environment variable
editor-cmd runtime configuration option
VISUAL environment variable
EDITOR environment variable
Possibly, a fallback value built into the Subversion libraries (not present in the official builds)
I have investigated these places and have not found how the default text editor is set on my computer:
Not using --editor-cmd option when committing
SVN_EDITOR environment variable not set
editor-cmd is not set in either my ~/.subversion/config, nor in /etc/subversion/config. Both of these files exist, but the line is commented out.
VISUAL environment variable not set
EDITOR environment variable not set
I'm downloading the official repository, so there should be no fallback.
There must be another place where the default can be set. Does anybody know?
Edit: There was a suggestion that Subversion might be calling /usr/bin/editor, and this is not set up on my co-worker's machine. I discovered that /usr/bin/editor is set up the same on both my system and my co-worker's system.
When you download the source directly (and build it - assuming you have the build dependencies met) you specify (or you can omit it) the default fallback editor. Normally source builds are done with something like this on Ubuntu (assume I have extracted/downloaded the subversion 1.8.10 source from here):
./configure
make
sudo make install
Notice the ./configure command above doesn't specify any options. The defaults will install to the prefix /usr/local . Prior to issuing those commands (on Ubuntu 12.04) I ran sudo apt-get build-dep subversion . I then did the commands above to build and install. I made sure that options 1-5 (In the OPs question) were not satisfied and then tried to commit a change to a repository. I got this as a response:
svn: E205007: Commit failed (details follow):
svn: E205007: Could not use external editor to fetch log message; consider setting the $SVN_EDITOR environment variable or using the --message (-m) or --file (-F) options
svn: E205007: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and no 'editor-cmd' run-time configuration option was found
Since I didn't remove the official Ubuntu subversion I had to run mine as /usr/local/bin/svn to make sure I was using the one I built. I could have used sudo apt-get remove subversion to remove the official one as well just to make sure.
Now if one runs these commands to rebuild the source:
make clean
./configure --with-editor=/usr/bin/editor
make
sudo make install
One should find that if options 1 to 5 are not satisfied and this version of subversion is run it should default to running whatever /usr/bin/editor points to. On Ubuntu that will depend on what alternative is being used.
So when Ubuntu does an official build where does their fallback editor come from? I went to the 12.04 source repository for subversion at this link . On the right hand side I downloaded the diff file subversion_1.6.17dfsg-3ubuntu3.4.diff.gz . I opened up the diff file Ubuntu uses and scrolling down you can find they use this set of ./configure options (flags):
confflags := \
--prefix=/usr \
--libdir=$(libdir) \
--mandir=\$${prefix}/share/man \
--with-apr=/usr \
--with-apr-util=/usr \
--with-neon=/usr \
--with-serf=/usr \
--with-berkeley-db=:::db \
--with-sasl=/usr \
--with-editor=/usr/bin/editor \
--with-ruby-sitedir=/usr/lib/ruby \
--with-swig=/usr \
--with-kwallet \
--with-gnome-keyring
The bold entry shows that they use /usr/bin/editor as their fallback.
I have built subversion 1.8.10 from source on Ubuntu 12.04 and got the expected behavior. This suggests one of these possibilities:
On one of the systems the options 1 through 5 is actually met.
One version of subversion was built with the --with-editor configure flag (either directly or indirectly). The fallback would point to whatever the --with-editor configure flag was set to.
On one of the systems the wrong version of subversion is being run. One possibility is that the official subversion on Ubuntu is in fact being used. If that is the case it was built to use /usr/bin/editor as a fallback.
On one of your systems you have an alias (or equivalent) for svn that specifies an editor. Aliases would be specified in a startup script like ~/.bashrc, ~/.bash_profile, /etc/bash.bashrc for example.
I think the normal way to specify this on Linux and other Unix-like systems, is to set the VISUAL environment variable (for GUI editors) or the EDITOR variable (for editors running in a terminal).
Try this:
update-alternatives --display editor
Run strings on your svn binary to see if it mentions Vim or any related env vars inside.
Also committing under strace -f may reveal something.
Set this in your .bashrc file.
Don't forget to "source .bashrc" or reopen terminal.
export SVN_EDITOR='vim'

Resources