sqrt36 / dotfiles

Personal configuration files
1 stars 0 forks source link

Alias to edit config file: permission denied #1

Open sqrt36 opened 7 years ago

sqrt36 commented 7 years ago

Description

Immediately after logging in, if you try to edit a config file with its alias, such as vimrc or zcustom, you get a permission denied error.

commander@cherokee [02:39:45 PM] [~] 
-> % vimrc
zsh: permission denied: /home/commander/.vimrc
commander@cherokee [02:39:54 PM] [~] 
-> % zcustom
zsh: permission denied: /home/commander/.oh-my-zsh/custom/plugins/custom/custom.plugin.zsh

This does not happen when editing the file directly or with the zshrc command.

commander@cherokee [02:44:37 PM] [~] 
-> % vi ~/.vimrc && echo success
success

File permissions

commander@cherokee [03:01:57 PM] [~] 
-> % ll ~/dotfiles 
total 32K
-rw-r--r-- 1 commander commander 1.4K Apr  6 13:16 custom.plugin.zsh
-rwxr-xr-x 1 commander commander 1.7K Apr  6 13:51 deploy
-rw-r--r-- 1 commander commander  395 Apr  6 12:33 gitconfig
-rw-r--r-- 1 commander commander  793 Apr  6 14:34 README.md
-rw-r--r-- 1 commander commander 2.8K Apr  6 12:33 tmux.conf
-rw-r--r-- 1 commander commander 2.3K Apr  6 12:33 vimrc
-rw-r--r-- 1 commander commander 2.9K Apr  6 12:33 zshrc

Workaround

When the zshrc is re-sourced, the error no longer occurs.

commander@cherokee [02:44:50 PM] [~] 
-> % zource

Alternatively, when you start tmux or log into a new zsh, the zshrc is sourced, so the error does not occur.

sqrt36 commented 7 years ago

Update

Cause

The problem lies with how the shell interprets the $EDITOR variable. When you run which on the aliases before the zource, it shows the variable as empty.

root@vance-origin [09:31:48 PM] [~]
-> # which zcustom
zcustom=' /root/.oh-my-zsh/custom/plugins/custom/custom.plugin.zsh'

After the zource:

root@vance-origin [09:32:07 PM] [~]
-> # zource; which zcustom
zcustom='vim /root/.oh-my-zsh/custom/plugins/custom/custom.plugin.zsh'
/usr/bin/vim

However, if you echo the value of the $EDITOR variable, before the zource, you can see that it is assigned.

root@vance-origin [09:37:48 PM] [~]
-> # echo 
vim