Running emacs completely from usb on windows [duplicate] - windows

This question already has answers here:
How can I have a portable Emacs?
(5 answers)
Closed 9 years ago.
In few weeks I'll be on a competition for website development.
I can use Emacs from a usb stick. I can't write to system drives anything so all Emacs configs and plugins are needed to be loaded from the usb stick. These are rules so I would rather not break them.
So I think this can be done with setting load-path or recompiling emacs to look config files from the usb but I no idea how this would be done in practice.

GNU provides compiled binary releases of Emacs for Windows. They require no installation or compilation.
Download the version you want (the latest at the time of writing is emacs-24.3-bin-i386.zip).
Optionally, verify its signature with GnuPG.
Extract it to your flash drive.
If a %HOME% environment variable exists, Emacs will use this as your home directory. Setting %HOME% to D:\ will cause Emacs to read its configuration from D:\.emacs or D:\.emacs.d\init.el. It will also cause package.el to install packages to D:\.emacs.d\elpa\.
If you are permitted to modify environment variables for your user, go to Computer ⟶ Properties ⟶ Advanced system settings, click the Environment Variables button, and add or modify HOME, setting it whatever drive letter your flash drive gets assigned. You will need to reboot (or at least log out and back in) before this variable takes effect.
If you are not allowed to modify this variable, you can use set HOME=D:\ in cmd.exe, then execute Emacs from that shell. You may want to write a short batch script to do this and add it to your flash drive.
To run Emacs, use bin\runemacs.exe.

Related

How to call system open from bash script

I've hooked the system call to typedef int (*orig_open_f_type)(const char *__file, int __oflag, ...); and thus, whenever a file gets opened, my code gets the event before it is passed on to the system. I created a dynamic library that overrides the open call and inject this library using DYLD_INSERT_LIBRARIES - working on a Mac machine and using XCode. It is a standard step that enables me to hook calls.
Now, I have bash script in which I have some files that I want to open. I have tried xdg-open , cat, exec - but they are not triggering the system call to open the file.
How should I invoke this open call in my bash script?
Please note that I have tested my open call hook, by opening files in C code.
I believe you're running foul of Apple's SIP (System Integrity Protection) which is designed to stop people doing things like that with system-provided executables. SIP was added to Mac OS X El Capitan (10.11) and continues in macOS Sierra (10.12).
To demonstrate whether this is the problem, consider copying /bin/cat to /usr/local/bin/cat and then try hooking (running) the local copy. You might get away with it there. This 'workaround' is purely for demonstration purposes. Basically, if I'm right, SIP is Apple's way of saying "don't go messing with our software".
You can follow links from Can Mac OS X El Capitan run software compiled for Yosemite that expects libraries in /usr/gnu/lib? to find out more about SIP. Following links via What is the "rootless" feature in El Capitan, really? on Ask Different to a blog article on System Integrity Protection, it says explicitly:
Runtime protection
SIP’s protections are not limited to protecting the system from filesystem changes. There are also system calls which are now restricted in their functionality.
task_for_pid() / processor_set_tasks() fail with EPERM
Mach special ports are reset on exec(2)
dyld environment variables are ignored
DTrace probes unavailable
However, SIP does not block inspection by the developer of their own applications while they’re being developed. Xcode’s tools will continue to allow apps to be inspected and debugged during the development process.
For more details on this, I recommend taking a look at Apple’s developer documentation for SIP.
Emphasis added
Basically, this means that you won't be able to hook calls to the open() system call for Apple-supplied software installed in the system directories. You will need to rethink what you are trying to do.
Running any normal command -- like cat -- that processes a file will cause the file to be opened. You can also open a file (and immediately close it) using the shell syntax:
: < /path/to/file
If your system call hook isn't getting called, something must be wrong with your hook -- there's no way these commands are working without opening the file. Alas, you haven't explained how you implemented your hook, so we have no way of debugging that.
The file command opens the file to look at its contents.
$ file /path/to/file
I have suggested this because it eventually leads to having the system call open which can be confirmed using strace.
$ strace file /path/to/file 2>&1 | grep open
I thought one of the good things about using file is that it opens the file in read only mode. In comparison to other ideas, unlike cat, it will not have to run through the entire file, just part of it, so the time complexity using file may be constant. Unlike vim, which someone has suggested, file will return when finished and not block like a text editor would.

Setting global environment variables in windows programatically [duplicate]

This question already has answers here:
How to set a variable for the current OS session only
(3 answers)
Closed 7 years ago.
As i am frequently moving desktop, I use a lot of portable apps.
I would, however like to alter/add global environment variables programtaically
on startup so that it is available to all consoles and windows in general.
Preferably It should work by running a script.
As the computer may be used later by another person the settings and variables must disappear when rebooted or powerloss occours.
Examples:
I would like to add imagemagick to the PATH on startup
Add to global CLASSPATH on startup.
Any surgestions?
Just set the traditional way. Go to the System Applet, set your user variables.

Dynamic user home directory on Windows (changing %HOMEDRIVE% and %HOMEPATH%)

Actual question
How can I "redirect" (symbolic links?) or temporarily change the values of %HOMEDRIVE% and %HOMEPATH% (maybe based on two batch scripts that change the values when I start working at the machine and reset everything after I'm done)?
Background
A lot of Windows programs pick up either system variable %USERPROFILE% or a combination of %HOMEDRIVE% and %HOMEPATH in order to figure out where a user's "home" directory is that they need to use (e.g. C:\Users\JohnDoe). Being a fan of the philosophy of portable apps (see at the bottom what I mean by that), I'm wondering if I could somehow make my home directory portable, i.e. have it point to a directory on a portable device. Or, in other words, I would like to make it "dynamically changeable".
What I tried
I've read a bit about Set and Setx and tried this:
Finding out what the current variable values are:
C:\Users\JohnDoe> Set HOME
HOMEDRIVE=C:
HOMEPATH=\Users\<username>
Set them:
C:\Users\JohnDoe> Setx HOMEDRIVE "d:"
C:\Users\JohnDoe> Setx HOMEPATH "\home"
That creates HOMEDIR and HOMEPATH as user-specific environment variables (see Control Panel >> System >> Environment Variables). But the "global ones" did not change and e.g. RStudio will not recognize the user-specific variables (still writes to C:\Users\JohnDoes\[...]).
C:\Users\JohnDoe> Set HOME
HOMEDRIVE=C:
HOMEPATH=\Users\<username>
Portable Apps
For example, see PortableApps.com or simply think "software that simply has been installed to a portable device instead of C:\Program Files\<app-name>". The latter works a treat for me for programs that don't really care about %HOMEDRIVE% and %HOMEPATH% (e.g. Eclipse or R).
Some others (e.g. Git) just need to be tweaked a little bit (e.g. see this post).
Yet some others (e.g. RStudio) run in fact smoothly off the portable device, but write stuff to the user's "home" directory. That's the kind of software that I would like to tell to use a directory on my portable device instead.
While you can change the environment variables this wont work for all applications, as there is also a Shell folder API in Windows which gives various user specific locations.
So it is better to use the actual Windows method to change the profile. And no this will not be possible to be a mobile device as it expects a stable and available location for the registry database of the user.
I think when setting up windows (and with sysprep) one can specify a location for the }users} folder (different drive). The quickest thing to move are the special library folders, you can change their location in the Explorer Properties view.

Is there any way to prevent ncurses based programs from running?

Hey there, I'm building a remote shell server that interfaces between a text-only client and a virtual shell.
It works perfectly when using regular shell commands, but the first thing that people try after that is vim, which promptly drives my server crazy and can't even be closed remotely.
Is there any way to detect ncurses based programs and prevent them from running in my special shell?
(the server is ruby, but any system command will do)
You can declare the capabilities your shell has, by setting the TERM environment variable to the correct value. For instance, if your shell has the same capabilities as the vt100 terminal, export TERM to the correct value, and programs like vim will respect that.
To run vim in vt100-mode, try:
TERM=vt100 vim
You could also try:
export TERM=dumb
The trick is to find a terminal that corresponds to the capabilities of what you are creating. There is a lot to choose from. On my system (Arch Linux) this gives me a long list of choices:
find /usr/share/terminfo
You might be able to find a terminal specification that corresponds to what your program can handle.
Alternatively, you may want to consider implementing terminal emulation for ansi or vt100:
http://en.wikipedia.org/wiki/ANSI_escape_code
http://www.termsys.demon.co.uk/vtansi.htm
Best of luck!

How can I have a portable Emacs?

Is there a way run Emacs from a USB drive? I am a Windows user and I would like to be able use it on any PC without an Emacs install.
Yes, the "normal" Emacs distribution for Windows is precompiled and just runs without having to do any install. Just get one of the *.zip files from the usual place, unpack it onto a USB disk, and you can use it directly. (The actual binary is inside the "bin/" directory.)
The only thing you may want to do is set it up to look for ".emacs" always on the USB disk instead of on your hard drive; see
(info "(emacs) Windows HOME")
on how to do that.
You can read Emacs-related pages at PortableApps.com, and if they have not yet ported Emacs to their set of portable applications, then please ask them kindly to add Emacs to the list of text editors. With enough requests they will do this eventually.
There is a beta version of a Portable Apps version of emacs 23.2 here. Initial test works fine here.
Create a directory in the root of your USB drive called home.
Create site-start.el in the site-lisp folder and then copy this and you are all set to go.
(defvar %~dp0 (substring data-directory 0 3))
(defvar usb-home-dir (concat %~dp0 "home/"))
(setenv "HOME" usb-home-dir)
I have ported emacs to portable apps format.
http://esnm.sourceforge.net/download.html

Resources