Go Back   The macosxhints Forums > OS X Help Requests > UNIX - General



Reply
 
Thread Tools Rating: Thread Rating: 42 votes, 5.00 average. Display Modes
Old 11-13-2002, 11:20 AM   #21
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
Quote:
Originally posted by Titanium Man ...open a new term window, and try typing 'exec zsh'. This will launch zsh, but it won't be a sub-shell of tcsh...

it won't be a login shell, either.

to fully exercise your zsh startup, try:

% zsh -l # or --login, to get a login shell
__________________
On a clear disk, you can seek forever.
mervTormel is offline   Reply With Quote
Old 11-13-2002, 10:01 PM   #22
vonleigh
All Star
 
Join Date: Jan 2002
Posts: 579
Hello,

I was using just plain zsh. I tried using exec zsh but the result was the same, what actually did work is changing the prefs of terminal so that /bin/zsh gets executed when opening a new window.

Edit: Tried zsh -l and --login and that didn't work either, still got that (2) there.

Edit2: eek, found out what it was that was screwing my paths I had:

source /etc/profile

In my .zshrc. Taking that out fixed it.

---
So all I need now is some color in my ls and one last question and I'm done! Sorry for dragging on this thread for so long.

Oh, and on the colorized ls, I need the fink ls right?

And the second question: I have a function that adds someone to my blocked list, the function needs to be run as sudo though. Before I had an alias that said basically "sudo function", is there a less kludgy way of doing it? Or would It be recommended i run sudo function every time.

Last, timan mentioned that I don't have to put braces and function name in my function, is it ok to have it either way? looks a little more organized with it.


----------------
Edit3:

Eek! I thought I was all done, but now I have a new problem... ::sigh:: I hope that once I get it running I can forget about shells for about a year. Look at this:

Code:
% ls -a
ls: -a: No such file or directory
Does that make any sense at all? If I explicitly tell it the path it works (say ls -a /) but If I omit it, it isn't smart enough to use the current dir.


thanks,
V

Last edited by vonleigh; 11-13-2002 at 10:13 PM.
vonleigh is offline   Reply With Quote
Old 11-13-2002, 10:30 PM   #23
Titanium Man
Guest
 
Posts: n/a
Good to hear that you got your PATH straightened out. I have colorized ls which I got from fileutils via fink. I wish there were a way to use /bin/ls and get a colorized ls, though. It sounds like you have ls aliased to something, so doublecheck that. Also try the full path: /bin/ls -a and see what happens. I'm not sure about a better way to include sudo within an alias; maybe someone else could anwer that one. As far as functions in ~/.zfuncs go, I think you can leave them in brackets if you like, but I'm pretty new to the whole zfuncs thing myself, so I'd check the documentation: 'man zshall' and http://zsh.sourceforge.net/
  Reply With Quote
Old 11-14-2002, 02:37 AM   #24
vonleigh
All Star
 
Join Date: Jan 2002
Posts: 579
You are absolutely right, ls was aliased to #alias ls="ls --color=auto", so how do you do it so that you get color and the switches work?

Also, my ll function doesn't work, and I'm very much used to using it, so any ideas on how to get it to work? Basically it's the same issue, it needs an explicit path to work, here's what it looks like:

Code:
ls -lag "$*" | more
I'm wondering if I have to do something like the following (which doesn't work obviously) but I'd appreciate any pointers:

Code:
ll () {
if ("$*" == nil) "$*" = `cwd`
fi
ls -lag "$*" | more
}
Edit: I just realized the above is pretty dumb, because if $* is empty, it would evaluate ti ls -lag | more, which is exactly what I want. How come it doesn't work?

My pid getter, with no arguments, spits out all the pids there are; yet ll doesn't work even though the code is pretty much identical. What say the wizards?


V

Last edited by vonleigh; 11-14-2002 at 05:44 AM.
vonleigh is offline   Reply With Quote
Old 11-14-2002, 09:16 AM   #25
pmccann
Major Leaguer
 
Join Date: Jan 2002
Location: Adelaide, South Australia
Posts: 470
Sorry, too tired for a detailed answer just now, but here's a nasty, shallow, miserly couple of lines.

Your simple "ll" function works fine for me. In my ~/.zsh_functions directory I made a file called "ll" with a single line in it: exactly as you posted above...

ls -lag "$*" | more

Bingo: ll is available and works as you'd like it to. Are you sure that "ls" alias isn't running round in your shell as some kind of remnant/revenant?

As for colour: sorry, I'm an "lc" person! One of very few, I'm sure, but it does what I want quite nicely (particularly when it's set up via "persistent perl", which is verging on decadence for such a simple script; but that's the joy of having a machine with a modern processor and stacks of memory sitting on your desktop!). If you've no idea what I'm talking about see the search field. Or --even easier-- just play with the script at the end of the following page: it should cut and paste fine: call it "lc", dump it in ~/bin, make it executable, and then "rehash".

http://forums.macosxhints.com/showth...c&pagenumber=2

As above, it's pretty basic, but does have some virtues! Speed's probably not one of them.

Cheers,
Paul (who is recycling far too much lately; yech, starting to smell like a compost heap whenever I post...)
pmccann is offline   Reply With Quote
Old 11-14-2002, 10:11 AM   #26
Titanium Man
Guest
 
Posts: n/a
Yep. seems like that ll of yours should work. I did the following:

% echo 'ls -lag "$*" | more' > .zfuncs/ll

When I opened up a new shell, 'll .' got me the listing of the current directory. Why don't you create a test user, one who doesn't have all of your predefined aliases and settings, and test? Bear in mind that I have

fpath=($zdotdir/.zfuncs $fpath)
autoload -U +X ${fpath[1]}/*(:t)

in my .zshenv, and that you should have something like that there too in order for the functions to work. I think.

Edit:

PS, you won't get color using ll, because it's piped to 'more'
  Reply With Quote
Old 11-14-2002, 10:24 AM   #27
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
Quote:
Originally posted by Titanium Man
...PS, you won't get color using ll, because it's piped to 'more'

ls --color dir listings are gloriously ansi-tinted in more here presently; it is less that no habla color.

--the "obtuse comment fruitbat"
mervTormel is offline   Reply With Quote
Old 11-14-2002, 10:35 AM   #28
Titanium Man
Guest
 
Posts: n/a
Aha, it's because I had --color=auto set, instead of just --color. Thanks merv
  Reply With Quote
Old 11-14-2002, 06:19 PM   #29
santin
Triple-A Player
 
Join Date: Jan 2002
Location: Madrid
Posts: 71
Sorry, for joining so late to this thread... been busy lately...

Vonleigh, would you please post your zsh init files so we all can try to solve your problem... of course, if there is something you don't want to show (confidential things) you simply cut it away and done...

For the record, you can create your functions without the surrounding brackets as long as each function is in its own file, if you want to put several functions in one file they must be bracketed.
santin is offline   Reply With Quote
Old 11-14-2002, 06:58 PM   #30
vonleigh
All Star
 
Join Date: Jan 2002
Posts: 579
pmccann,

Thanks for your response. First I want to thank you for lc, that command is just beautiful, and it avoids me having to install findutils. Not that I have anything against them, but it installs a bunch of additional stuff like anacron, etc. that I'd prefer to avoid.

Timan, the problem isn't with ll+directory, but just plain ll. For example "ll ." works, but not ll by itself; aka with no arguments.

Santin, bienvenido al tema.

Oh, and I found yet another problem... this is getting horrible. I can't run screen, and I looove using screen, here's what happens:

Code:
%screen
... snipped all the usual ...
[screen is terminating]
So basically instead of staying on that screen that says "press space to continue" it goes directly to "screen is terminating"

Oh, and a quick question while I'm at it. Say I issue a command and get "permission denied", any quick way, with zsh, of doing sudo #something, with #something meaning the last command you issued exactly? Say I do "mv something /somewhere else", and it gives me an error, is there a quick command for sudo XYZ that will do "sudo mv something /somewhere/else"?

I have no idea why ll doesn't work then. I did notice something odd, I edited my ll so that it was on just one line (no brackets), closed and restarted my terminal, yet which ll doesn't match cat ll:

Code:
% which ls
/bin/ls

% which ll
ll () {
        ls -lag "$*" | more
}

% cat .zfuncs/ll
ls -lag "$*"| more

% ll
ls: : No such file or directory
And finally here are my .zshrc and .zshenv as they stand:


Code:
% cat .zshenv | fold -60
umask 027

PATH=$HOME/bin:/usr/local/bin:/usr/local/lib:/usr/bin:/bin:/
usr/X11R6/lib:/usr/X11R6/include/X11:/usr/local/sbin:/usr/sb
in:/sbin:/usr/lib:/X11R6/bin:/Developer/Tools
export PATH
MANPATH=/usr/share/man:/usr/bin/man:/usr/local/man:/usr/loca
l/share/man:/usr/X11/man:/usr/man:~/man
export MANPATH

MAIL=/var/mail/$USER

cdpath=(~)
zdotdir=$HOME
fpath=($zdotdir/.zfuncs $fpath)
autoload -U +X ${fpath[1]}/*(:t)

Code:
% cat .zshrc | fold -60 
# zsh init file

export PATH=${PATH}:/Developer/Tools
export EDITOR=pico
## Get rid of dups in paths
typeset -U path cdpath manpath fpath

# Autoloads
autoload -U compinit
compinit -C

# ALIASES
#alias ls="ls --color=auto"
alias -- ..='cd ..'
alias sshnn="ssh -l user server.org"
alias sshmt="ssh -l user server.com"
alias sql="mysql -u root -p"
alias buildmail="sudo /etc/mail/build"

# PROMPT
# PROMPT='%n@%m> '
# RPROMPT=' %~'     # prompt for right side of screen
myprompt () {
local WHITE=$'%{\e[0;37m%}'
local GREEN=$'%{\e[0;32m%}'
local NOCLR=$'%{\e[0;0m%}'
local RED=$'%{\e[0;31m%}'
local BLUE=$'%{\e[0;34m%}'
local CYAN=$'%{\e[0;36m%}'
local VIOLET=$'%{\e[0;35m%}'
local NEWLINE=$'\n'
if [ $UID = 0 ]; then #I am root
PS1="${CYAN}{${RED}%(00t:DING!:%D{%I:%M %p}) 
%~${CYAN}}$BLUE%(2L:(%L):)$CYAN%# $
{NOCLR}"
else #I'm not root
PS1="${CYAN}{${WHITE}%(00t:DING!:%D{%I:%M %p}) 
%~${CYAN}}$BLUE%(2L:(%L):)$CYAN%# ${NOCLR}"
fi
}
myprompt


# HISTORY
HISTFILE=~/.zshhistory
HISTSIZE=3000
SAVEHIST=3000

# OPTIONS
# to show and tab through options
setopt MENU_COMPLETE
# so multiple shells share history
setopt INC_APPEND_HISTORY
## case-insensitive (all),partial-word and then substring co
mpletion
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r
:|[._-]=* r:|=*' 'l:|=* r:|=*'
# so history is searchable with arrows
bindkey "^[[A" up-line-or-search ## up arrow for back-histor
y-search
bindkey "^[[B" down-line-or-search ## down arrow for fwd-his
tory-search


# eliminated this whole section since it was giving me trouble, read below.
# These statements aren't in my .zshrc btw.

# fink
[ -f /sw/bin/init.sh ] && source /sw/bin/init.sh
fortune -a

Last edited by vonleigh; 11-14-2002 at 08:25 PM.
vonleigh is offline   Reply With Quote
Old 11-14-2002, 07:13 PM   #31
santin
Triple-A Player
 
Join Date: Jan 2002
Location: Madrid
Posts: 71
Substitute
Code:
ls -lag "$*" | more
for
Code:
ls -lag $* | more
that should make it for ll...
santin is offline   Reply With Quote
Old 11-14-2002, 07:24 PM   #32
vonleigh
All Star
 
Join Date: Jan 2002
Posts: 579
Santin,

Perfect! It works now, thanks alot. Any ideas on the screen issue though? Also, I found something new:

Code:
% sudo -s
Unknown colorls variable `do'.
So I can't become root either. This switch is becomming increasingly difficult, thanks all for your help, it is very much appreciated. Without you guys I would've given up a long time ago (I'm sure some of you _want_ me to give up )

Edit: I commented out my color section and it works now (both sudo -s and screen). But here's something odd, if I do screen or sudo -s it drops me into a tcsh shell instead of a zsh shell. Any ideas?

And I'm still wondering about some way of quick sudo last command.


v

Last edited by vonleigh; 11-14-2002 at 07:28 PM.
vonleigh is offline   Reply With Quote
Old 11-14-2002, 07:35 PM   #33
santin
Triple-A Player
 
Join Date: Jan 2002
Location: Madrid
Posts: 71
Nothing about screen... yet.

However, here you have what you wanted for sudo
Code:
% command
% sudo !-1
It will sudo the last command you entered.

As for the problem with the colors variable do, I usually got the same problem, it seems that that variable (I don't know what it is for) is not supported so I strip it out from LS_COLORS:
Code:
eval `dircolors 2>& /dev/null | sed 's/:do=..;..://'`
Let's see if we find something for screen... which screen are you using, Jaguar's or fink's?

Last edited by santin; 11-14-2002 at 07:41 PM.
santin is offline   Reply With Quote
Old 11-14-2002, 07:49 PM   #34
vonleigh
All Star
 
Join Date: Jan 2002
Posts: 579
Hello,

Thanks for the !-1, that will avoid some unnecessary typing.

I'm using jaguar's screen. I wonder why both sudo -s and screen drop me to tcsh, maybe I'm missing a setting somewhere, I'll google it just in case.



thanks,
v
vonleigh is offline   Reply With Quote
Old 11-14-2002, 07:58 PM   #35
santin
Triple-A Player
 
Join Date: Jan 2002
Location: Madrid
Posts: 71
Have you tried sudo -s and screen after stripping out the do variable from LS_COLORS?

I think it may be the cause of your problems...

Hope you get to solve it, I'm going to bed now as it is a bit late here in Spain...

Hasta mañana!
santin is offline   Reply With Quote
Old 11-14-2002, 08:23 PM   #36
vonleigh
All Star
 
Join Date: Jan 2002
Posts: 579
Hello,

I actually eliminated that whole section from my zshrc (export ls colors and the definition) since I'm using Paul's lc.

Closed, opened a new session but still it drops me to tcsh on screen and sudo -s.

Que duermas bien, gracias por la ayuda.



v
vonleigh is offline   Reply With Quote
Old 11-14-2002, 08:38 PM   #37
vonleigh
All Star
 
Join Date: Jan 2002
Posts: 579
Wohoo!

Figured it out: Netinfo. Changed my shell to /bin/zsh instead of /bin/tcsh. Now screen and tcsh put me in the right shells.

Now I have trouble with the prompt, lol. Maybe the prompt wizards can help me out:

Standard prompt:

Code:
{05:35 PM 
~}%
Screen prompt:

Code:
{05:36 PM 
~}(2)%
Root prompt (after sudo -s):

Code:
{05:36 PM 
~}(2)# $
{NOCLR}
I don't really mind the (2) in the screen prompt, but the root prompt is really odd (also everything I type comes out green). Here's the code I got from timan for the prompt:

myprompt () {
local WHITE=$'%{\e[0;37m%}'
local GREEN=$'%{\e[0;32m%}'
local NOCLR=$'%{\e[0;0m%}'
local RED=$'%{\e[0;31m%}'
local BLUE=$'%{\e[0;34m%}'
local CYAN=$'%{\e[0;36m%}'
local VIOLET=$'%{\e[0;35m%}'
local NEWLINE=$'\n'
if [ $UID = 0 ]; then #I am root
PS1="${CYAN}{${RED}%(00t:DING!:%D{%I:%M %p})
%~${CYAN}}$BLUE%(2L:(%L):)$CYAN%# $
{NOCLR}"
else #I'm not root
PS1="${CYAN}{${WHITE}%(00t:DING!:%D{%I:%M %p})
%~${CYAN}}$BLUE%(2L:(%L):)$CYAN%# ${NOCLR}"
fi
}


So all and all I think i'm ready to start using zsh full time! I guess all that's missing is some good prompt customizing to get it just... perfect.

Thanks all for a very enlightening journey, now it's time to have fun :)

v

[edit: smilies off -mt]

Last edited by vonleigh; 11-14-2002 at 08:49 PM.
vonleigh is offline   Reply With Quote
Old 11-14-2002, 10:04 PM   #38
Titanium Man
Guest
 
Posts: n/a
Whoops! First, you should put 'fortune -a' in ~/.zprofile, not ~/.zshrc. Second, let me give you the prompt with the correct spacing:

myprompt () {
local WHITE=$'%{\e[0;37m%}'
local GREEN=$'%{\e[0;32m%}'
local NOCLR=$'%{\e[0;0m%}'
local RED=$'%{\e[0;31m%}'
local BLUE=$'%{\e[0;34m%}'
local CYAN=$'%{\e[0;36m%}'
local VIOLET=$'%{\e[0;35m%}'
if [ $UID = 0 ]; then #I am root
echo ""
echo "CHEATS ENABLED"
PS1="${CYAN}{${RED}%(00t:DING!:%D{%I:%M%p})%~${CYAN}}$BLUE%(2L:(%L):)${CYAN}%# ${NOCLR}"
else #I'm not root
PS1="${CYAN}{${WHITE}%(00t:DING!:%D{%I:%M %p}) %~${CYAN}}$BLUE%(2L:(%L):)${CYAN}%# ${NOCLR}"
fi
}
myprompt

I'm glad this is starting to come together for you. ¿Y como es que alguien llamado vonleigh (que no es un nombre hispano) habla español? Then again, I gues Titanium Man isn't a Hispanic name either ;-)

Last edited by Titanium Man; 11-14-2002 at 10:30 PM.
  Reply With Quote
Old 11-14-2002, 11:05 PM   #39
vonleigh
All Star
 
Join Date: Jan 2002
Posts: 579
Hello,

Ah good, the prompt behaves a lot better now. I tried putting fortune -a in my .zprofile but I get:

/Users/username/.zprofile:1: command not found: fortune

So I guess the profile is being run before finks init.sh. I guess I'll leave it in my .zshrc for now unless someone has a better suggestion. But I can see the problems with it being there, as fortune gets run at odd moments.

The prompt still gives me a (2) in both root and screen mode, is that on purpose? I tried creating a second screen within the first in case it would maybe change to (3) or so, but it stayed at (2).


Edit: Uhm... now that it's practically working perfectly, hows about sharing some of these wonderful tips that make it so nice to use zsh? Any custom functions? ideas tips and tricks?

I did follow the earlier thread, so I'm thinking beyond those.

v


P.D: lo que pasa es que soy de Venezuela; de ahí que el español es mi lengua materna. Tampoco pensé que titanium Man hablara español

Last edited by vonleigh; 11-14-2002 at 11:10 PM.
vonleigh is offline   Reply With Quote
Old 11-14-2002, 11:44 PM   #40
Titanium Man
Guest
 
Posts: n/a
Regarding 'fortune -a' not working, that's odd; I'm not sure what's going on yet (works fine for me). I can, however, fix the number 2 appearing in your prompt if you don't like it. It's there because when you do 'sudo -s' you start a subshell:

% echo $SHLVL
1
% sudo -s
Password:
# echo $SHLVL
2

So I include %(2L:(%L):) in my PS1 so I know if I'm in a subshell or what. If you want to remove that, you can do this as your prompt:

myprompt () {
local WHITE=$'%{\e[0;37m%}'
local GREEN=$'%{\e[0;32m%}'
local NOCLR=$'%{\e[0;0m%}'
local RED=$'%{\e[0;31m%}'
local BLUE=$'%{\e[0;34m%}'
local CYAN=$'%{\e[0;36m%}'
local VIOLET=$'%{\e[0;35m%}'
local NEWLINE=$'\n'
if [ $UID = 0 ]; then #I am root
echo ""
echo "CHEATS ENABLED"
PS1="${CYAN}{${RED}%(00t:DING!:%D{%I:%M %p}) %~${CYAN}}%# ${NOCLR}"
else #I'm not root
PS1="${CYAN}{${WHITE}%(00t:DING!:%D{%I:%M %p}) %~${CYAN}}%# ${NOCLR}"
fi
}
myprompt

As for simple reasons I like zsh:
If I want to list only directories:

% ls -d *(/)

If I want to list only files:

% ls *(.)

I can autocomplete man pages by typing a few letters and hitting the Tab key:

% man if
if if_indextoname if_nametoindex ifnames
if_freenameindex if_nameindex ifconfig


Note that to do this you have to put

compdef _man

in your .zshrc. There is a TON of other stuff that can be done just using zsh as an interactive shell (ie even if you never write a single shell script). But read through the man pages, and check out http://zsh.sourceforge.net/Doc/Relea..._13.html#SEC59
  Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 10:42 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.