I work in an environment where we all log in as ourselves, then sudo to a common user. (Bleah). I'm starting to use emacs and would like to specify my own .emacs file at launch. What I think I want is to specify the location of .emacs with an environment variable, but I don't see any way to do that in the emacs documentation. Is there one?
As an alternative, perhaps I need to learn elisp and conditionally load my own file out of the common .emacs file located in /home/common_user/.emacs? In my case, I already have an environment variable SUDO_USER set to my name 'lcuff', and an environment variable MY_CONF set to /foo/bar/blah/lcuff, wherein I'd like to store my own .emacs file. How would I do this?
Thoughts and advice appreciated.
See:
C-hig (emacs) Find Init RET
Failing anything else, you can specify $HOME for a command with env:
env HOME=/foo/bar/blah/lcuff emacs
Invoking emacs with the -u option will seek the init file for the given user, so
emacs -u Leonard
will run emacs with your emacs initialization file, even if you are logged in as another user.
You can tell emacs to load the init file of your choice by saying:
emacs -q -l /path/to/my/preferred/.emacs
It's a little bit tricky working out who emacs thinks you are. From info:
More precisely, Emacs first determines which user's init file to use.
It gets your user name from the environment variables LOGNAME and
USER; if neither of those exists, it uses effective user-ID. If that
user name matches the real user-ID, then Emacs uses `HOME'; otherwise,
it looks up the home directory corresponding to that user name in the
system's data base of users.
So I'd start first with finding out who emacs thinks you are, by starting emacs
without loading any init files:
emacs -q
and then find out where emacs thinks your init file is:
(locate-user-emacs-file "yourrealusername")
I think on a fresh home environment it will default to
~/.emacs.d/yourusername, but that should help you decide where best to place
the init file.
An important point is that it's pretty good practice to have an emacs user
directory rather than just a startup file. There is a heap of extra guff
that emacs needs to keep track of (package management, customized settings,
backup files, dictionary, manually inserted lisp code etc etc) and I find it extremely useful to put all
this stuff in the one spot. Emacs looks in ~/.emacs.d/init.el if it doesn't
see ~/.emacs or ~/.emacs.el on the system. Make sure you don't have ~/.emacs
still.
Create a new file called ~/.emacs.d/init.el
Put this in it:
(setq user-emacs-directory "~/.emacs.d/")
(message "This is my init.el file and noone elses!!!")
(inhibit-default-init) ;; there might be a default.el lurking somewhere
If emacs got your username and home right, you can then restart with:
emacs -u therealme
or, if it stuffs up the environment variables
env HOME=/this/is/my/home USER=blah emacs
There just might be a site-start.el somewhere that might get loaded before
your init.el. If you suspect this, loading emacs with the --no-site-file
option will nuke this.
Related
On my ArchLinux number cruncher I have two accounts: A user account (benj) and the root account.
For administrative tasks I ssh into the machine using my user account. With the shell open, I switch to root using su .
Running emacs now shows an error that something went wrong during initialisation
Warning (initialization): An error occurred while loading ‘/home/benj/.emacs.d/init.el’:
File is missing: Cannot open load file, No such file or directory, ~/.emacs.d/init-modules/emacs-lisp-package-archive.el
To ensure normal operation, you should investigate and remove the cause of the error in your initialization file. Start Emacs with the ‘--debug-init’ option to view a complete error backtrace.
My ~benj/.emacs.d/init.el is modular while ~root/.emacs.d/init.el is not. I don't understand why emacs is trying to load my user's configuration file.
echo $HOME # Shows /root
alias | grep emacs # Shows nothing
which emacs # /user/bin/emacs
emacs --version # GNU Emacs 26.1
# Copyright (C) 2018 Free Software Foundation, Inc.
# GNU Emacs comes with ABSOLUTELY NO WARRANTY.
# You may redistribute copies of GNU Emacs
# under the terms of the GNU General Public License.
# For more information about these matters, see the file named COPYING.
However, when logging into root on TTY1 , M-x describe-variable on user-init-file returns the expected /root/.emacs.d/init.el
C-hig (emacs)Find Init says:
How Emacs Finds Your Init File
Normally Emacs uses the environment variable ‘HOME’ (*note HOME: General
Variables.) to find ‘.emacs’; that’s what ‘~’ means in a file name. If
‘.emacs’ is not found inside ‘~/’ (nor ‘.emacs.el’), Emacs looks for
‘~/.emacs.d/init.el’ (which, like ‘~/.emacs.el’, can be byte-compiled).
However, if you run Emacs from a shell started by ‘su’, Emacs tries
to find your own ‘.emacs’, not that of the user you are currently
pretending to be. The idea is that you should get your own editor
customizations even if you are running as the super user.
More precisely, Emacs first determines which user’s init file to use.
It gets your user name from the environment variables ‘LOGNAME’ and
‘USER’; if neither of those exists, it uses effective user-ID. If that
user name matches the real user-ID, then Emacs uses ‘HOME’; otherwise,
it looks up the home directory corresponding to that user name in the
system’s data base of users.
There is a nice option when setting up zsh on Ubuntu
Populate your ~/.zshrc with the configuration recommended
by the system administrator and exit (you will need to edit
the file by hand, if so desired).
However, on a fresh Arch Linux install the option is missing. Is there a way to have it (or maybe, I am being picky here) ?
This happens when you haven't got a .zshrc and there's a /etc/zsh/recommended.zshrc. If you say yes, it'll just copy that one to .zshrc.
Arch, bare-bones awesomesauce that it is, doesn't bother to ship such a file.
I am using NodeJS version 4.2.1
I want to know the command for clearing the NodeJS REPL console history completely so it doesn't show previously executed commands when Up or Down arrow keys are pressed.
Any suggestions ?
The answer is actually simple :)
On Windows (my version is 10):
go to user folder: cd %userprofile%
empty file named .node_repl_history (in my case with vim text-editor) OR you can simple run: echo. > .node_repl_history and it will have same effect.
Per the nodejs documentation which can be found at the following link:
nodejs repl
Environment Variable Options
The built-in repl (invoked by running
node or node -i) may be controlled via the following environment
variables:
NODE_REPL_HISTORY - When a valid path is given, persistent REPL
history will be saved to the specified file rather than
.node_repl_history in the user's home directory. Setting this value to
"" will disable persistent REPL history. NODE_REPL_HISTORY_SIZE -
defaults to 1000. Controls how many lines of history will be persisted
if history is available. Must be a positive number. NODE_REPL_MODE -
may be any of sloppy, strict, or magic. Defaults to magic, which will
automatically run "strict mode only" statements in strict mode.
Persistent History
By default, the REPL will persist history between
node REPL sessions by saving to a .node_repl_history file in the
user's home directory. This can be disabled by setting the environment
variable NODE_REPL_HISTORY="".
I think you might be looking for console.clear(). At least as of v8.3.0 https://doc.codingdict.com/nodejs-ref/console.html#console_console_clear :)
There is a program in the PATH variable installed by root, but I installed a more recent version in my local.
There is any way to make my program preferable instead of the root?
Sorry for my bad english.
export PATH="/path/to/my/local/directory:$PATH"
Set this in your shell's startup file (e.g., ~/.bash_profile or ~/.zshenv) and restart your shell (or just execute it in your terminal).
put the preferred directory in front of the other one. It will pick up the first one it finds.
export PATH=/this/path/is/searched/first:/this/one/is/second:$PATH
Hey, I'm trying to have a graphical program and I want it to start after I log in. How do I do so? I know there's a GUI program, but I want to use a command line here.
GUI tool:
http://www.thegeekstuff.com/2009/07/ubuntu-open-applications-automatically-during-system-startup/
now, there is update-rc.d, however, it seems to run before I log in, while the entire system loads ups (Unless I don't understand what the NN means in the update-rc.d manual).
Any ideas?
There's also an autostart folder in ~/.config/autostart - which is profile (or user) specific. If you put a .desktop file in /etc/xdg/autostart it will become a global startup for any new users created. This assumes you have xdg-user-dirs-gtk installed.
Drop a .desktop file in... /etc/xdg/autostart here, might be different on Ubuntu.