Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Emacs use my .bashrc file?

Tags:

I need to use my $PATH in Emacs to run some commands. How can I make Emacs use it? I installed Emacs from Ubuntu repositories.

like image 972
Sławosz Avatar asked Jun 20 '11 12:06

Sławosz


People also ask

Where do I put the .bashrc file?

In most cases, the bashrc is a hidden file that lives in your home directory, its path is ~/. bashrc or {USER}/. bashrc with {USER} being the login currently in use.

What is use of ~/ bashrc?

The . bashrc file is a script file that's executed when a user logs in. The file itself contains a series of configurations for the terminal session. This includes setting up or enabling: coloring, completion, shell history, command aliases, and more.

How do I open a .bashrc file?

The quickest way to access it is nano ~/. bashrc from a terminal (replace nano with whatever you like to use). If this is not present in a user's home folder the system-wide . bashrc is used as a fallback as it is loaded before the user's file.

What is a bashrc file?

In the shell script, run whenever the Bash computer is started is what can be called a bashrc file. This command line interface (CLI) and terminal application, which runs on both servers and on mobile devices, determines how the OS will run. Bashrc File In Windows?

How do I edit a bashrc in Linux?

Use nano ~/.bashrc to open and edit the .bashrc file. (This will create the file if it does not yet exist) if not in home directory, you can just copy from /etc/bash.bashrc, and make it source for your terminal, by typing in your terminal source .bashrc from your home directory after copying.

How do I copy a bashrc from another directory?

If .bashrc is not in your home folder, even after you list the hidden files, you can copy it from: if not in home directory, you can just copy from /etc/bash.bashrc, and make it source for your terminal, by typing in your terminal source .bashrc from your home directory after copying.

Do I need a bashrc?

You could simply copy and paste it (with root permissions of course), but a .bashrc is not entirely essential (it may be required to make things work. I haven't found out) at a user level as it mostly overrides the system-wide one with user-specific tweaks.


1 Answers

Here's a trick I use to ensure my GUI Emacs always sees the same $PATH that I get inside a shell:

(defun set-exec-path-from-shell-PATH ()   (let ((path-from-shell (replace-regexp-in-string                           "[ \t\n]*$"                           ""                           (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))     (setenv "PATH" path-from-shell)     (setq eshell-path-env path-from-shell) ; for eshell users     (setq exec-path (split-string path-from-shell path-separator))))  (when window-system (set-exec-path-from-shell-PATH)) 

Specifically, on OS X, a graphical Emacs will not pick up the user's shell's definition of $PATH, so this trick helps me on that platform.

Update: this code has now been published as an elisp library called exec-path-from-shell and installable packages are available in MELPA.

like image 170
sanityinc Avatar answered Sep 22 '22 17:09

sanityinc