how do I change default editor for sudo vipw from "vi" to "vim" by tcsh in FreeBSD - editor

When I use command sudo vipw to edit my password file, It's always use vi as editor. I don't like this very much and want to change it to vim.
I already tried:
Add export EDITOR=/usr/local/bin/vim in /etc/profile.
But shell told me "export: Command not found". I thought the reason is export is built-in function only in bash. And I don't want to change my shell.
AddEDITOR=/usr/lcoal/bin/vim in default block of /etc/login.conf
Add setenv EDITOR vim in /root/.cshrc, /.cshrc, ~/.cshrc
All above didn't work at all.
I have google for hours but could not find anything help.

Your /etc/sudoers file doesn't keep your EDITOR environment variable.
I personally have an /etc/sudoers.d/local file, something like
# We don't need to worry about wheel users breaking in to get root access because they already have it.
Defaults:%wheel env_keep+="HOME EDITOR",!set_home,shell_noargs
I'm not sure why this isn't the default, since wheel users have already been given full access. But it's apparently prevailing wisdom to continue hassling them.
Note: If you're using an older /etc/sudoers file that doesn't support an /etc/sudoers.d directory, these lines can be dropped in there... or you could add #includedir /etc/sudoers.d as the last line of your /etc/sudoers file to enable an /etc/sudoers.d directory. Um, yes, the # is a required part of that line, because someone thought it was important for that directive to look like a comment.

Try adding this to the root user /root/.chsrc:
setenv EDITOR vim
or to set it globally to all users using shell tcsh/csh add it in /etc/csh.cshrc
From the man:
A login shell begins by executing commands from the system files /etc/csh.cshrc
and /etc/csh.login. It then executes commands from files in the user's home directory:
first ~/.tcshrc or, if ~/.tcshrc is not found, ~/.cshrc ...
Non-login shells read only /etc/csh.cshrc and ~/.tcshrc or ~/.cshrc on startup.
Also verify vim is installed since is not by default, you could try:
pkg install vim-console

setting the EDITOR or VISUAL environment variable is the key.
if you don't want to go to the trouble of modifying config files (which is indeed the long term solution) then you could sudo su - to get to the root prompt and then you could export EDITOR=/usr/bin/vim before running vipw

There is an empty file called .selected_editor in $HOME (/root).
Remove it and the next call to vipw will ask you to select the editor.

Related

where the $PATH is created in ubuntu (16.04) and how to change it

when checking my $PATH on ubuntu (16.04)
I get a long list of directories, few of which even do not exist in my file
system, and some of them I just don't need:
echo $PATH
.../usr/games:/usr/local/games:/snap/bin
where they are created and how can I remove them?
I wnant to control the creation of the $PATH, rather than
correct it later by the tricks described in
https://unix.stackexchange.com/questions/108873/removing-a-directory-from-path
Some typical places where $PATH can be set when starting up a bash shell on Ubuntu include:
/etc/profile
~/.profile
~/.bashrc
where ~ represents your home directory.
Also look at any scripts called by those scripts.
There may be other things that get called when starting up a bash shell, depending on various conditions. For details, take a look at the INVOCATION section from the command:
$ man bash
See this answer from askubuntu.com to edit the path either using a text editor or the command line.
I found the answer to your question today. The path you want to edit is in /etc/environment.

Setting path in Solaris Sparc

I have one python command file, i want to set it as a PATH in Solaris Sparc so that i can easily use my command from anywhere. For example the file name is abc.py and it contains abc --version to display version of file abc. So, after opening terminal i should only give command abc --version and it should display version of abc.
The architecture (SPARC) has nothing to do with the PATH which is more a shell thing but you do not tell what shell you are using.
Anyway, if you use a bourne style shell, i.e. not csh/tcsh, and you don't mind this to affect every user account on that host, you might add the wanted path to the PATH setting in the file /etc/profile.
When abc.py is located in your homedir, you can start it with ~/abc.py.
You need to call the file abc.py with abc.py, not abc (and have a shebang line which instructs the shell where it can find python).
When you want to start the file with ./abc, you can rename the file to abc (the shebang will tell it is python, not the .py), or introduce an alias:
alias abc="~/abc.py"
Using an alias can be an alternative for adding a shebang line:
alias abc="/usr/bin/python abc.py"
When you do not want to use an alias you can make a bin dir and put abc there.
I will add the shebang for you:
mkdir ~/bin
echo "#!/usr/bin/python" > ~/bin/abc
cat abc.py >> ~/bin/abc
chmod +x ~/bin/abc
mv abc.py bin/abc.py.old
Now change your login PATH with PATH=${PATH}:$HOME/bin in your .profile or .bashrc, and login again (or source the login script).

Run script from dock in Mac OS X

I am developing web applications using Ruby on Rails and Sublime Text 3 on OS X 10.8.4. I recently installed the package RubyTest. The tests only work when Sublime is launched using the command
subl
in terminal. Otherwise I get the error message:
/bin/sh: rspec: command not found
I think that's meant to be the case; that's implied in RubyTest's readme file on github.
However I'd like to retain the ability to launch from the dock. Is there a way I can do this?
Unfortunately, OSX applications do not pick up on your $PATH variable set in Terminal. To change the internal PATH settings in Mountain Lion (this method hasn't been tested with previous versions, although it should work), you'll need to edit /etc/launchd.conf:
Make sure you have admin privileges.
Open Terminal or your favorite substitute and see if there's anything in the file /etc/launchd.conf:
cat /etc/launchd.conf
If you get an error like
cat: /etc/launchd.con: No such file or directory
then continue with the next step. If the cat command does display some content, copy it to the clipboard.
Create a new text file with the following content, modified to fit your needs:
setenv PATH /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/Users/YourUserName/bin:/path/to/gems/bin
If the cat command displayed some content in the previous step, paste it into the new file before the setenv PATH command. If it already contains a setenv PATH command, just modify it to add the directories you need, such as /path/to/gems/bin
Save the new file in your home directory (/Users/YourUserName) as launchd.conf.
Go back to Terminal and enter:
sudo mv ~/launchd.conf /etc
to use admin power to move the new file to /etc, replacing anything that was there before. Depending on your previous usage of the sudo command, you may get a short "be careful doing what you're doing" message, but either way you'll need to enter your password. /etc is not directly accessible through the Save dialog unless you're a real power user and know how to get around OSX's file system restrictions.
Reboot your computer
And you should be all set. If you're interested, launchd and launchctl use the csh/tcsh syntax, so you can't use the bash/zsh export PATH=/usr/local/bin:... format.

How to pass env variables to GNOME

I want to replace some utilities(like telnet) with transparent wrappers(with loggers).
At first I used aliases, that worked nicely at the command line but gnome doesn't understand shell aliases so that when people would launch the utilities as the shell for a gnome-terminal profile it would run the actual utility instead of the wrapper.
Then I tried adding new folder with symlinks and prepended it to PATH(security isn't a huge concern plus its a special folder just for these symlinks) in ~/.bashrc but they still run the original(I'm guessing gnome doesn't run .bashrc since it works from the command line). Any ideas where setting path needs to go?
Maybe update-alternatives fits your needs?
I found two ways to do this that seem to work like I want(sourcing scripts for gnome env).
First putting it in ${HOME}/.gnomerc (but I found some places that say you should manually exec gnome session afterwards and others that don't(It seems to work fine without it) and I'm afraid of breaking login.)
Putting it in ~/.profile seems to work so I just
echo 'PATH=~/.symlink_dir/:${PATH}' > ~/.profile
(note that this is ignored by bash if a ~/.bash_profile exists so you may want to manually source it from ~/.bash_profile just in case
echo 'source ~/.profile' >> ~/.bash_profile).
If you really want to use your replacement utilities throughout, you could put symlinks to your replacements in /usr/bin/ (or wherever as appropriate) and move the originals to /usr/bin/originals/ (or wherever).
If you do that, you'd better make sure that your wrappers are rock solid though. Depending on what you're replacing, errors might prevent booting, which is generally undesirable.
It might not be what you are asking, but have you tried changing the commands of the launchers from the menu editor.
If you are using Gnome 3 you will have to download the alacarte package.

How to permanently change sudo's $PATH variable (Ubuntu 9.x)

I want add some directory to the $PATH when running sudo, this is a (semi) permanent requirement, not something that needs to be added to the scripts themselves. I notice that Django has managed to do it, (my $PATH when running sudo is "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin:/django/django-trunk/django/bin") - so how did it do that?
This is the line in the sudoers file that resets:
Defaults env_reset
You can work around this by adding PATH to env_keeps or by adding this line:
Defaults env_keep = "PATH"
EDIT: meder, you do not disable env_reset, you simply bypass the path reset
Or you can remove the offending env_reset line.
Even better though, you can declare a secure_path that will replace PATH when sudo is run:
Defaults secure_path="/bin:/usr/bin"
That way you can control what specific directories to include in the path.
I think this should work out if you save it in /root/.bashrc:
export PATH=/www/foo:$PATH
I forget if it's PATH or PYTHONPATH and if it actually matters, this is based on my user's .bashrc:
export PYTHONPATH=/www/django:$PYTHONPATH
You can set the variable in /etc/environment, and then use "sudo -i" to run the script (works in ubuntu 10.10).

Resources