how to place a file inside .bashrc - emacs

I am following a tutorial on the link https://github.com/birlrobotics/birl_baxter/wiki and I was told as folows:
Finally, after doing catkin_make, place the newly created ~/ros/indigo/catkin_ws/devel/setup.bash file inside .bashrc
cd ~
emacs .bashrc
source ~/ros/indigo/rbx_ws/devel/setup.bash
When I run the command emacs .bashrc the emacs editor opens but I am not sure what I am expected to do after that .

The tutorial asks you to open your .bashrc file with the extensible editor Emacs by executingemacs .bashrc. Then you are supposed to add the line source ~/ros/indigo/rbx_ws/devel/setup.bash at the end of the file.
Then you exit the editor Emacs with the key stroke "C-x C-c" meaning you press the Control/CTRL key, hold it and then press first the 'x' key and then the 'c' key. After this you continue the tutorial.
Otherwise you can just:
echo "source ~/ros/indigo/rbx_ws/devel/setup.bash" >> ~/.bashrc in your terminal without using the editor Emacs.

Related

iPython shell - how to use $EDITOR to edit commands

In a terminal emulator with readline support, I can use key binding Ctrl-X Ctrl-E to bring up $EDITOR to edit a command.
How do I do that in iPython to bring up $EDITOR to edit half-finished code?
P.S. My $EDITOR is set to "vim -u ".
shortcuts used:
'g' to launch gvim with the content of current cell (you can replace gvim with whatever text editor you like).
so, when you want to edit the cell with your preferred editor, hit 'g', make the changes you want to the cell, save the file in your editor (and then quit), then press 'u'.

Zsh alternative for Bash

Can someone tell me the zsh command for vmstat ? Also is there any link that lists out all these zsh equivalents? I keep stumbling upon this problem all the time when I'm trying to do something. Thanks
vmstat is the same in both shells (and all shells), you probably just don't have your PATH set correctly.
The Fix:
In your bash terminal (just type bash to open the bash terminal) type: which vmstat, you should see a path return.
Now, append this to your PATH in your .zshrc file with:
OUTPUT="$(which vmstat)";echo "export PATH=\""${OUTPUT}":\$PATH\"" >> ~/.zshrc
Switch to zsh by typing: zsh
Now source your .zshrc with:
. ~/.zshrc
Your PATH should be corrected.
Optional:
If you have just switched to zsh and you had a simple .bashrc file, one thing you could do is move everything from your .bashrc to your .zshrc. Just run:
cat ~/.bashrc >> ~/.zshrc
This will append everything in your .bashrc to your .zshrc.
Now source your .zshrc with:
. ~/.zshrc
Your PATH should be corrected, but you may want to manually example your .zshrc file for redundancies.

Open a folder in Sublime Text 3 using command line

I'm trying to open a directory in sublime Text 3.
I can launch sublime from the command line using the subl command.
The help text show the following:
Sublime Text build 3059
Usage: subl [arguments] [files] edit the given files
or: subl [arguments] [directories] open the given directories
or: subl [arguments] - edit stdin
Arguments:
--project <project>: Load the given project
--command <command>: Run the given command
-n or --new-window: Open a new window
-a or --add: Add folders to the current window
-w or --wait: Wait for the files to be closed before returning
-b or --background: Don't activate the application
-s or --stay: Keep the application activated after closing the file
-h or --help: Show help (this message) and exit
-v or --version: Show version and exit
--wait is implied if reading from stdin. Use --stay to not switch back
to the terminal when a file is closed (only relevant if waiting for a file).
Filenames may be given a :line or :line:column suffix to open at a specific
location.
Thus to open a directory I should be able to use the following
subl ./folder_name
but that does not work for me. Sublime does open (with a empty new document) and I cannot see the folder in the side bar.
Am I doing it wrong...
BTW. I'm using the fish shell with the 'Oh my fish' Add-on (I have also added the sublime add- on)...
Mac Or Linux Only
The best & safest way to do this is to create a symbolic link from the Sublime executable file (subl) to a folder already in your $PATH (e.g. /usr/local/bin/). If you do this; you won't have to update this every time sublime updates...
For users running BASH (i.e. most people):
ln -s '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl' /usr/local/bin/subl
If that doesn't work, create a bin folder in your home directory (if one does not already exist), add it to your PATH variable and create a soft link to that file).
mkdir $HOME/bin
export PATH=$HOME/bin:$PATH
ln -s '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl' $HOME/bin/subl
Then before you start using it properly, I would suggest taking a look at the help text first, which explains it's usage:
subl -h
e.g.
subl my_folder_name/filename.txt
subl my_folder_name
to open a file and folder in Sublime respectively.
Taking it a step further
I use a BASH function to take this a step further with the following benefits:
shorten the shortcut to just s (which is somewhat shorter than subl).
automatically open the current directory that you are if no file/directory is specified after subl / s.
If you want, you can use this function by running the following (after running the above):
cd
subl .bashrc
This should open the .bashrc file in Sublime Text. Add the following to the bottom.
function s {
if [ "$1" != "" ]; then
subl $1
else
subl $PWD
fi
}
Then you can open Sublime by simply typing in a s (all the sublime arguments still work)...
(Side Point, I also use a similar function for open (for mac) / or xdg-open (for ubuntu); where I shorten the command to just o. I use it a lot to open the current directory in the file manager)...
Fish Shell Users (you know who you are)
The export line above will not work; so exchange it for the following
set PATH $HOME/bin:$PATH
Before Edit
I had different versions of the command line subl and sublime text three installed. I simply removed the subl command and then re-added and that fixed the problem for me...
For those who may find this useful - this is what I did:
subl -v
This showed me the build of the command-line sublime, when I checked this against the version of my actual Sublime, I noticed that the command line subl was an older build. So I tried to find the location of the command line subl using the following command (for me this was /usr/bin/subl):
which subl
So I first removed this older command-line sublime text.
sudo rm /usr/bin/subl (use `sudo` only if necessary)
And then re-added Subl to my PATH (as above)
To open sublime in the same folder you can simply type in your commandline:
subl .
In order to work you must configure some stuff:
1) To prevent the opening of previous projects you should set the following properties of your Sublime User Settings:
"hot_exit": false,
"remember_open_files": false
2) In order to use subl.exe from anywhere you should add the Sublime folder in the environment variables. I.e.
C:\Program Files\Sublime Text 3
That's because by default the side bar does not show, you can show the side bar by
View > Side Bar> Show Side Bar
[1
I've had this issue before, on both Mac OSX and Windows, and I found some oddities with it;
Mac OSX
You either have to have Sublime Text open already for the subl ./folder_name command to actually open the folder, or Sublime must have been quit with windows still open - if you close all the windows then quit Sublime, using the subl ./folder_name command will just open a blank Sublime window.
Windows
You have to have Sublime open for the subl ./folder_name to work. Without Sublime open, it will just open a blank Sublime window.
I've yet to find a way of the command opening fine, no matter how you quit Sublime / when you have Sublime closed.
Try having Sublime open whilst you run the command, and see if it works then.
To open a folder as a project in Sublime Text, use subl . while in the folder you're trying to open.
Linux
So if you want to open ~/Documents/folder_name, then move to that folder in Terminal cd Documents/folder_name and type the command subl .
Note This was only tested in Ubuntu with Sublime Text 2.
Edit Answer found here: http://olivierlacan.com/posts/launch-sublime-text-3-from-the-command-line/
I was having trouble opening sublime text 3 with sublime text 2 currently installed. To fix this issue:
1) open /usr/local/bin from terminal.
2) locate and delete subl within bin folder
3) copy and pasted '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl' /usr/local/bin/subl into terminal.
4) locate new subl within bin folder
5) used subl in terminal to verify command opens sublime text 3 properly.
6) used subl -v and got Sublime Text Build 3083
MAC OSX Open terminal and run following command:
ln -s '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl'
/usr/local/bin/subl
The above command is needed only for first time. After this configuration, whenever you go to folder where your project is present, run following command:
subl .
While there are already multiple answers and I apologize for adding to the noise, I don't understand why you're using subl ./folder_name to open a local directory. Why not use subl folder_name/ instead?
Either way my ST3 (build 3083) installation on OS X is opening a child directory with either subl ./child or subl child/ whether Sublime was open prior to the command or not.
PS: Make sure you don't have the sidebar closed when opening directories by running Command + K then B. I've often assumed a directory was failing to open just because I had my sidebar closed and couldn't see the files listed inside of it.
There is probably an alias with the name subl provided by 'Oh my fish' . You can check if there is an alias by using alias command in the terminal. This will display all aliases for your session. If you have it on the list then it is colliding with your symbolic link. Disable the alias by fixing the source or by using unalias subl (unalias will only fix it for the current session)
I had this problem when using bash-it aliases for osx. Disabling it fixed the problem for me.
For Linux and MacOs users and Sublime Text 3
Try the command :
subl3

emacs on Windows: .emacs is no valid file name

I've found out where to put my .emacs file, but it seems it can't begin with a ".".
I tried naming it "emacs" or "_emacs", but how can I find out if it is used?
You can always create the file using Emacs itself: C-x C-f ~/.emacs. The ~ represents your home directory, which you can set as environment variable HOME.
Have a look at this page and this one for start up instructions.
If you are creating a file in Explorer, it won't allow you to use a .name (gives this error).
A simple work-around, if you have bash (cygwin, git-bash, or any other variant) installed is to use that to rename the file. It may also work in powershell or command prompt, I've not tested those.
Files can start with '.', this doesn't cause any trouble alone, but explorer won't let you name them with it.
Windows Explorer disallows the creation of filenames starting with a dot. A simple workaround with builtin Windows tools is to create the file with a dummy name (eg. _emacs), then use cmd.exe to rename it:
cd path/to/file
ren _emacs .emacs
Recent versions of windows (e.g. Windows 7) seem to allow creation of a .emacs file using windows explorer. When creating/renaming the file simply enter .emacs. instead of .emacs.
To test if the .emacs that you are editing is the .emacs that is being loaded, you could put the following elisp command in it:
(minibuffer-message "it worked")
Now exit and restart emacs, while watching the minibuffer at the bottom of the screen to see if it appears (it will only appear for 2 seconds).
Windows allows the creation and use of that type of file, but Windows Explorer does not allow a file to be named to that using Windows Explorer. Use another tool (like the command line, or emacs) to create the file with that name.

Changing the default folder in Emacs

I am fairly new to Emacs and I have been trying to figure out how to change the default folder for C-x C-f on start-up. For instance when I first load Emacs and hit C-x C-f its default folder is C:\emacs\emacs-21.3\bin, but I would rather it be the desktop. I believe there is some way to customize the .emacs file to do this, but I am still unsure what that is.
Update: There are three solutions to the problem that I found to work, however I believe solution 3 is Windows only.
Solution 1: Add (cd "C:/Users/Name/Desktop") to the .emacs file
Solution 2: Add (setq default-directory "C:/Documents and Settings/USER_NAME/Desktop/") to the .emacs file
Solution 3: Right click the Emacs short cut, hit properties and change the start in field to the desired directory.
You didn't say so, but it sounds like you're starting Emacs from a Windows shortcut.
The directory that you see with c-x c-f is the cwd, in Emacs terms, the default-directory (a variable).
When you start Emacs using an MS Windows shortcut, the default-directory is initially the folder (directory) specified in the "Start In" field of the shortcut properties. Right click the shortcut, select Properties, and type the path to your desktop in the Start In field.
If you're using Emacs from the command line, default-directory starts as the directory where you started Emacs (the cwd).
This approach is better than editing your .emacs file, since it will allow you to have more than one shortcuts with more than one starting directory, and it lets you have the normal command line behavior of Emacs if you need it.
CWD = current working directory = PWD = present working directory. It makes a lot more sense at the command line than in a GUI.
I think the line you need to add to your .emacs is is
(setq default-directory "C:/Documents and Settings/USER NAME/Desktop/" )
Emacs will start in your desktop that way, unless you have a file open. It will usually start in the same directory as the file in your current buffer otherwise.
You can type the 'cd' emacs command. ( M-x cd ) to change the default folder as a one off.
I've put
(cd "c:/cvsroot/")
in my .emacs and it did the job
The default folder is actually the same as the current working folder for the buffer, i.e. it can be different for every file you work with. Say that the file you are working with is located in C:\dir_a, then the working directory for that buffer will by default be C:\dir_a. You can change this with M-x cd and type in whatever directory you would like to be the default instead (and by default I mean the one that will show up when you do C-x C-f).
If you start emacs without opening a file, you will end up with the *scratch* buffer open. If you started emacs from a Windows shortcut, the working directory will be the same as that specified in the shortcut properties. If you started it from the command line, it will be the directory from where you started it. You can still change this default directory with M-x cd, also from the *scratch* buffer.
Finally, you can do as Vadim suggests and put
(cd "c:/dir_a/")
in your .emacs file, to make that directory the default no matter how you start emacs.
As you're on Windows you can do it with a shortcut.
Create a shortcut to C:\emacs\emacs-21.3\bin\runemacs.exe. Edit the properties of the shortcut and change the value of Start In: to be whatever you want your default directory to be.
I am using emacs 22.2.1 under Windows XP and have been helped by the answers above to get the response in the minibuffer I want to the command C-x C-f. Initially I was getting
"Find file: C:\Program Files\emacs\bin/" like Anton.
I have HOME set to "C:\Documents and settings\USER NAME\My Documents".
The response to C-x C-f I want in the minibuffer is "Find file: ~/".
By adding (setq default-directory "C:/Documents and Settings/USER NAME/My Documents") to my .emacs file I was able to get the response "Find file: C:\Documents and settings\USER NAME\My Documents/" which is functionally the same as "Find file: ~/".
However, I noticed one further point. "Customize Emacs" under "Options" allowed me to inhibit the startup screen. Now when I open emacs I go immediately to the scratch buffer. When I type C-x C-f in the scratch buffer I get the exact response I want.
I have added to my shortcut (in Gnome, Linux) a pramater which is a blank dummy file name, and I specify the directory. Since my emacs defaults to "home" I simply say:
/Desktop/blank_file
and that opens a file called "blank_file"
That also moves the current working directory for that emacs session to the desktop.
If I happen to put stuff in "blank_file" then save it, of course, I've got that stuff saved. Which might be an annoyance or it might be a good thing, depending!
To change default directory to DESKTOP in Dired and shell put this in your ~/.emacs:
;;This works for Windows XP.
(setq default-directory (concat "C:\Documents and Settings\MY_ACCOUNT\DESKTOP\"))
For windows users, the best way that I found is to create the shortcut for runemacs.exe and placing the shortcut in the root directory of my notes folder.
This way, when you use this shortcut to open emacs, it will by default open in the root directory without having to specifically set the Start In property (you can leave the Start In property blank).
Reference: According to Microsoft, if you leave the 'Start In' box empty, the script will run in the current working directory
TIP:
Additionally, if you have organized your notes into multiple root folders (Personal, Work etc...), you can copy multiple such shortcuts in each folder to open various instances of emacs with their own default directories.
In Windows 8, it works to create a shortcut in the Desktop and change the property 'Start In:' for the shortcut.
Now, I ran the program emacs-23.3\bin\addpm.exe as recommended, and the Windows-8 screen (that horrendous invention from Microsoft) it appeared an icon-link to Emacs. But there you have to change again the property 'Start In'. (It is different from the one in the desktop).
Just right-click, choose in the bottom bar 'Open the file location' (or similar, I did it in my language), and you are taken to the folder with a new shortcut, in which you can (must) also change the property 'Start In:'.
A little involved, but in fact very easy.
Since the most annoying thing is having windows Emacs dump you into system32 when you are just using the shortcut, but want every other case to work, just use a bit of elisp...
(when (string< "C:\WINDOWS\system32" default-directory) (setq default-directory "~/"))
So it will only default to your home directory when you end up in system. The only drawback is if you really want to start emacs in system32...