Gentoo Archives: gentoo-user

From: daid kahl <daidxor@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] zsh and sudo [SOLVED]
Date: Tue, 02 Mar 2010 23:31:06
Message-Id: 3ac129341003021530k52b7d4fcl63ba22c6d9963434@mail.gmail.com
1 On 22 February 2010 01:33, daid kahl <daidxor@×××××.com> wrote:
2 >>> I just installed zsh recently and was working on making the switch
3 >>> over from bash for my daily user, provided I can get a few things
4 >>> worked out.
5 >
6 >> Zsh is a wonderfull shell, but it does have a steep learning curve, due to its
7 >> many features. Yes, you will bang your head on the wall many and many times if
8 >> you don't read the documentation and continue to think in bash terms.
9 >> Reading the manual (or the "user friendly" documentation) is a must. Zsh is an
10 >> example of an open source project with a massive and excellent documentation,
11 >> so no excuses for not reading it! :)
12 >
13
14 Forgive the reorganization and slight top-posting nature of this post.
15
16 Most of my googling to finish setting up zsh and resolve all my issues
17 now hits this thread! So since I've gotten everything worked out for
18 myself, here's what I've done (mostly from manuals and documentation,
19 but in any case...)
20
21 >>> The biggest problem that I can't find useful results googling is zsh
22 >>> interaction with sudo.
23 >>>
24 >>> I'm noticing some strange behavior with the PATH and also the
25 >>> interpretation of '='.
26 >>>
27 > [snip]
28 >>> So sudo has the PATH set correctly, but it doesn't actually use the
29 >>> correct path.  Fishy!
30 >>
31 >> Nope. If you do
32 >>
33 >> sudo echo $PATH
34 >>
35 >> $PATH is replaced by the calling shell before sudo even sees it, so no wonder
36 >> you see the right one (btw, this should also answer your other question on why
37 >> doing the same on a second instance of the shell seems to "work").
38 >> To test what path is seen when sudoing, do
39 >>
40 >> sudo zsh -c 'echo $PATH'
41 >>
42 >> that should be more accurate. But you already had an indication of what $PATH
43 >> is in your first command above.
44 >
45 > Yes, that's true!
46 >
47 >>
48 >> This might be a good read about where to define PATH:
49 >>
50 >> http://zsh.sourceforge.net/FAQ/zshfaq03.html#l19
51 >>
52
53 It's true, this told me what I needed to know.
54
55 So now I have critical path information in ~/.zprofile
56 daid@flux ~ % more .zprofile
57 #Basic PATH
58 export PATH="$PATH:/sbin:/usr/sbin"
59
60 And more specific pathing and variables in ~/.zshenv
61 (not boring you with details here)
62
63 >>> As for interpretation of '=' I really don't understand what's
64 >>> happening.  It seems indiscriminate of the case in terms of mucking
65 >>> about, but the exact result it not always the same.  Consider the
66 >>> monstrous output in the following simple case of making a new
67 >>> environment variable:
68
69 Yes, setting unsetopt EQUALS in ~/.zshrc works perfectly for me.
70
71 I also alluded to some other small points of confusion that I didn't
72 ask for help on. None-the-less, I explain how I successfully resolved
73 these issues in case it can be useful to anyone.
74
75 For slim, the issue was that I wanted to copy/paste the bash line in
76 /etc/slim.conf, but that's too lazy and naive. The following works
77 fine (and it would be nice if this was a commented option in the
78 default slim.conf for n00bs like me):
79 login_cmd exec /bin/zsh -l ~/.xinitrc %session
80
81 basically, the bash version has -login which zsh doesn't understand
82 and wants to take as -l -o -g -i -n
83
84 Honestly, bash's version should be --login based on standard gnu
85 styled options IMO.
86
87 For home/end keys, /etc/inputrc is not in a format zsh can understand,
88 so it's an issue to map these manual, say, in .zshrc
89
90 However, /etc/inputrc is commented well, and so one can look at that,
91 use Ctrl+V at the command line, and get the basic idea. The escape
92 key, denoted in config files as \e shows up from Ctrl+V at the command
93 line as ^[
94
95 I make a file called ~/.zinputrc which is sourced by ~/.zshrc
96 A sample line is:
97 bindkey "\eOH" beginning-of-line
98
99 I also find that some of my mappings change between console-login and
100 xterm mode, so in some cases I have to map things two ways, or
101 pick/choose if I have some collision (like Ctrl+Arrow in console mode
102 is the same as an arrow in xterm mode for my machine, so that means I
103 can't use it for word skipping. This could be an xinit issue, but in
104 any case, bash was not doing this either on my machine, so I've not
105 lost and functionality I was used to having. A topic for later
106 perhaps)
107
108 Also, if, for example, I use gcc-config to change compilers, then I
109 need to source /etc/profile. Well this borks up my nice zsh prompt.
110 So I edited /etc/profile so that it doesn't do this:
111
112 if [ -n "${BASH_VERSION}" ] ; then
113 # Newer bash ebuilds include /etc/bash/bashrc which will setup PS1
114 # including color. We leave out color here because not all
115 # terminals support it.
116 if [ -f /etc/bash/bashrc ] ; then
117 # Bash login shells run only /etc/profile
118 # Bash non-login shells run only /etc/bash/bashrc
119 # Since we want to run /etc/bash/bashrc regardless, we
120 source it
121 # from here. It is unfortunate that there is no way to do
122 # this *after* the user's .bash_profile runs (without putting
123 # it in the user's dot-files), but it shouldn't make any
124 # difference.
125 . /etc/bash/bashrc
126 else
127 PS1='\u@\h \w \$ '
128 fi
129 elif [ -n "${ZSH_VERSION}" ] ; then
130 PS1="%B%{$fg[yellow]%}%n@%m%{$reset_color%}%b
131 %B%{$fg[blue]%}%~ %%%{$reset_color%} %b"
132 else
133 # Setup a bland default prompt. Since this prompt should be useable
134 # on color and non-color terminals, as well as shells that don't
135 # understand sequences such as \h, don't put anything special in it.
136 PS1="${USER:-$(type whoami >/dev/null && whoami)}@$(type uname
137 >/dev/null && uname -n) \$ "
138 fi
139
140 All I've done is added the elif for ZSH_VERSION and then pasted my own
141 prompt there. This result is nearly identical to prompt gentoo,
142 except it gives a full path rather than just the working directory.
143
144 I can say that I was surprised how difficult migration to zsh is on a
145 Gentoo system, in the sense that some basic things, like keymaps and
146 /etc/profile are really just not designed to be compatible with zsh.
147 Whether or not they should be is a can of worms I won't touch, but I
148 would like to stress that the zsh Configuration and Installation Guide
149 in the gentoo handbook (http://www.gentoo.org/doc/en/zsh.xml) tells
150 you *none* of the things in this post, and I think that at least some
151 of them might warrant coverage. But that was updated about 30 months
152 ago, so maybe it's time for some changes...
153
154 Regards,
155 daid