![]() |
Switching to bash
Hello,
So I finally decided to make the switch to bash. I will hope that you can aid me a bit in this switch. 1. Do I have to change my default shell in netinfo from /bin/tcsh to /bin/bash? 2. How would I translate my aliases to bash, also my options? right now I have the following in my .cshrc: Code:
set path=($path /Developer/Tools .)Code:
set complete=enhanceCode:
setenv LESS "-Mice"Code:
alias gpid 'ps wwax | grep -i "\!*" | grep -v grep | awk '\''{print $1}'\'''Code:
source /sw/bin/init.csh3. Any other things I have to be careful when making the switch? anything I could've missed? Don't want to be bitten in the change. For example I just thought of the following, I followed the tcsh readme so I can have the 'll' command, with bash would i have this command or would i have to alias it myself? 4. Is there any changes in my day to day shell commands that I should be careful with? Like to the programs perform differently or something? I'm not too keen on what exactly it means to switch shells and what differences I should be aware of. Thanks in advance, V |
skip bash and go straight to zsh :D
whew! you really loaded this up. i suggest you keep your tcsh shell in tact as default while you get your bash legs and the bash startup ironed out in bash subshells. you'll be less crippled. % bash $ # now you're in a bash subshell $ exit # return to tcsh % bash --login # will exercise full login scriptage there are some scripts to translate aliases and env variables; i'll try and dig them up. they almost work ;] install a bash completion package - http://www.caliban.org/bash/index.shtml - this requires a little study find yourself a suitable ~/.inputrc file - i just looked at mine and i can't fathom where i got it. this is where you define key bindings and readline variables that dictate some behaviors, including completion. uh, bash aliases no habla command line args ( \!* in tcsh aliaii ), but functions do an ll function: ll () { ls -FlAh --color "$@" | more ; } your day to day commands should just work. NB: it is a considerable security risk to have the 'dot=current directory' in your path. more, later. take it slow, and get that bash subshell working. |
My tips:
These are the two entries I find essential for ~/.inputrc: Code:
set show-all-if-ambiguous on* The second is more controversial - I like it, but you may not. It does what you'd expect: remove case sensitivity in autompletion. As for .bashrc / .profile: * First of all, note that bash distinguishes between the common startup commands, and the login-only commands, just like tcsh does with .tcshrc and .login For example, entries in .profile will execute when you start up Terminal, but not for a subshell, such as if you do sudo -s do use a temporary root shell. For that reason I put almost all of my modifications in .bashrc *You can drop some of your specialized aliases, like the SSH aliases, since the caliban.org completion gives you kick-ass SSH server completion. * Prompt customization is similar, but uses the 'PS1' variable. For example, I put this in .bashrc: Code:
if [ $UID = 0 ]; then[mithras@hostname: Documents] for my prompt, or [root@hostname: Documents] at a root shell Have fun! |
Ditto and ditto. I also used to include
TAB: menu-complete in my .inputrc file. If you use fink, I believe the bash completion package that merv recommended is also available there (for those of use who DO like to keep all their eggs in one basket). The bash manpage is pretty darn helpful too. Of course, (and I don't mean to be a preachy zsh user) you could give zsh a whirl (merv did mention it already). It's an sh based shell with a lot of options right out of the box. Either way, I think you'll like your new choice better than tcsh once you get to know it a bit better. |
I have attempted to switch to bash several times - and it always seems to break too much for me to really enjoy it.
Are you jesting or should you really skip bash and go for zsh? |
zsh may have done a lot of things right. i dunno, i haven't investigated it enough for myself, but...
if: - you're new to shells - you feel you might be spending a good amount of time and effort in one - you wonder what the big deal is you might want to: - explore what the different shell families are - explore the caveats of the csh family - commit to one that will minimize your pain and service you for a long time |
Hello,
I've gotten a few opinions telling me to actually consider zsh instead of bash. My friend even posted me his (fairly long) zshrc for info. So while I'm at it: "- commit to one that will minimize your pain and service you for a long time" And that would be? :) Does zsh habla command line args? V |
So far I am not too thrilled...I entered zsh in terminal to give it a try...played a around a bit, checked out teh man pages, etc....then exited.
Now my terminal appears screwed. Whenever I open a terminal window all I get is a blank windwo, no prompt and the title bar sez "Command completed". If I close it and open it about 5 time I MIGHT get a promopt and often it sez NO MORE PROCESSES! Don't know what thats about - but I think thats why so many of us stick to the comfort fo csh. |
shot left: shocked and amazed
What did you DO! -- Chris Farley, Tommy Boy |
Quote:
% zsh -cisx ? yes |
Merv,
You lost me. If you're asking about the command line args statement, I meant as in my gpid or ll aliases (that would have to be handled by functions in bash, as you mentioned that bash no habla command line args). If you're refering to the "and that would be" i meant, which shell, in your opinion, would be the one that would: "minimize your pain and service you for a long time" V Edit: Bluehz I tried zsh and exited no problem, don't know why you're having trouble. I haven't updated to .2.2 yet though. |
Very weird - don't know what it was - log out/in seems to have solved it.
|
o i c. you made me read my own dreck. bash aliases no habla command line args.
as for zsh, i can't see that they do. an alias is just a value that gets expanded. re: minimize pain and to serve and protect... this is something that i can't answer for anyone. one must evaluate this themselves. |
bluezh, that sounds like something that happened to me when I first upgraded to OS 10.2, and that was resolved by moving ~/Library/Preferences/com.apple.Terminal.plist out of my Preferences folder and having it regenerate after logging out/back in. Weird. vonleigh, zsh is an sh based shell, as is bash, so aliases are set up the same way (and they're the same regarding command line args, I believe). Instead of using this (rather unsightly) alias:
alias gpid 'ps wwax | grep -i "\!*" | grep -v grep | awk '''{print $1}'''' I'd do this in bash or zsh: gpid () { ps ax | grep -i "$*" | grep -v grep | awk '{ print $1 }' } zsh allows you to have a specific directory where you store all your functions (one per file), and you don't have to enclose them in the normal brackets, so they look like a shell script. For example, the previous gpid function is in my ~/.zfuncs, and looks like this: % which gpid gpid () { ps ax | grep -i "$*" | grep -v grep | awk '{ print $1 }' } % cat .zfuncs/gpid ps ax | grep -i "$*" | grep -v grep | awk '{ print $1 }' bash, zsh, tcsh, whatever. In any case there is a lot to learn, so I think merv's advice about exploring various shells is good advice. If you're thinking about switching to a shell in the sh family (such as bash or zsh), the main differences you'll notice are when moving from tcsh to *sh. If you decide you don't like *sh, you can move to a different sh based shell with much fewer growing pains (the structure for setting up aliases won't change for example). Something else to consider is documentation. There are probably more bash users in the world, so it might be easier to get help with bash specific questions, but there are some knowledgeable zsh users who post here frequently (pmccann, OSXPEZ, santin, et al.) who have been helpful to me in learning about zsh. So flip a coin, pick a shell, and dive in. If you want to switch later, it won't be as big a deal as going from tcsh to *sh. |
After some deliberation (and the fact that my friend that helps me out uses this shell), I've decided to give zsh a try for now.
So I got crankin' and this is what i have so far, btw, great advice TiMan, although I think i'm missing something to make it work. I made my .zshfunc folder and put my gpid function in there as described and made it executable. Am I supposed to put that folder in my path? Maybe that's it. I also added two more functions, the ll function and the block function: Code:
% cat .zfuncs/llsomeone@somewhere REJECT (with a tab between the address and REJECT) Anyway, here's my .zshrc so far with comments: Code:
# zsh init fileCode:
# PROMPTCode:
# ALIASESBTW, broke it out on separate lines for readability, is only one line in the file. Code:
# HISTORYCode:
# OPTIONSThe inc_append_history is so that multiple shells write to the same history as the commands are executed. The last one is the best option my friend could find so that the auto-completion is case insensitive. It seems that it's deprecated, but it's the only way we could find so that cd d<tab> completes to Directory. Code:
source /sw/bin/init.csh* Things I'm still missing: 1. The ability to look back in history selectively. In other words if I type in "sudo" and click up arrow, I shouldn't be shown the history before, but the history before that starts with "sudo". 2. How to set my default editor as pico (instead of the yet unexplored emacs or vi). 3. How to get color ls and such. 4. I haven't tried moving my aliases over. Should I just include them in my .zshrc, and is the syntax any different? for example: alias sshnn 'ssh -l username server etc' Edit: I read up to earlier posts and loved the idea of different colored username for the prompt, but when I tried: Code:
if [ $UID = 0 ]; thenThanks, V |
Whew, that's quite a Christmas list you've got there, but I'll see what I can do. Check out www.dotfiles.com for some examples of a .zshrc file. Also, be sure to check out the documentation at http://zsh.sourceforge.net/. Ok about things in ~/.zfuncs, they don't have to be executable, and the don't have to have brackets:
% ls -l .zfuncs/gpid -rw-r----- 1 timan admin 57 Nov 3 23:50 ~/.zfuncs/gpid % cat ~/.zfuncs/gpid ps ax | grep -i "$*" | grep -v grep | awk '{ print $1 }' To get them to load automagically, I include autoload -U +X ${fpath[1]}/*(:t) in my .zshenv file. In fact, here's my .zshenv file (as it will solve your fink issue as well): 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/sbin:/sbin:/usr/lib:/X11R6/bin:/Developer/Tools export PATH MANPATH=/usr/share/man:/usr/bin/man:/usr/local/man:/usr/local/share/man:/usr/X11/man:/usr/man:~/man export MANPATH if [ -f /sw/bin/init.sh ]; then . /sw/bin/init.sh ; fi MAIL=/var/mail/$USER cdpath=(~) zdotdir=$HOME fpath=($zdotdir/.zfuncs $fpath) autoload -U +X ${fpath[1]}/*(:t) Here's a bit from my .zshrc that will answer your ls and editor questions: LS_COLORS='di=36:fi=32:ln=35:pi=5:so=5:bd=5:cd=5:or=31:mi=0:ex=31:*.rpm=90' export LS_COLORS myeditor () { if [ -e /sw/bin/nano ]; then export EDITOR='nano -cw' else export EDITOR='pico -w' fi } myeditor I've had to do 'export LS_COLORS' to get the colors to appear. The myeditor function is in case I don't have nano installed using fink, it'll default to pico. Regarding 'fortune -a', you'll want to put that in .zprofile, since that's for shells with output to a terminal, ie, interactive shells. Regarding your aliases, yes, many people do put them in their .zshrc file, but I got the idea from merv to put them in their own file (in my case it's called ~/.aliases), and I include the line if [ -f ~/.aliases ]; then . ~/.aliases ; fi in my .zshrc file. Hmm, what else? Oh, the prompt. The syntax is different in zsh and in bash. Here's mine: 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 Unwieldy as hell? Yep. Do a search on this forum (and others) on compinstall, or just type the command in and go with the flow (backup your .zshrc first). It takes 20 minutes or so to get set up (mainly because there're so many options), but you'll be able start taking advantage of zsh if you do. Oh, and one last tidbit before I sleep. Regarding ssh completetion, look here: http://forums.macosxhints.com/showth...&highlight=zsh By the way: I have no idea what I'm doing in zsh, so disregard everything you've just read :-) If I have a complaint about zsh, it's that there are maybe TOO MANY options. Anyway, search this forum for posts on zsh, check the manpages (man zshall), check out www.dotfiles.com and zsh.sourceforge.net, and post if you get stuck. I know that you'll be able to find help with zsh here if you need it, just as I have many times. Sorry for the hugemongous post, everyone. |
Hello,
Thanks for writing timan, unfortunately I'm still having some troubles: 1. I get the following error when I add: autoload -U +X ${fpath[1]}/*(:t) to my .zshenv file: /Users/vonleigh/.zshenv:3: no matches found: /usr/share/zsh/site-functions/*(:t) And my functions still don't work, the one I was trying was ll: % cat .zfuncs/ll ls -lag "$*" | more 2. I like your prompt, very interesting and amusingly it shows up in color, but here's what shows up: {11:42 PM ~}(2)% exit Is there supposed to be a 2 in there like that? what does yours look like? Last, my fink commands aren't being recognized, maybe I need to add the path somewhere; as in, if i type "fortune" i get command not found. Thanks, V |
Oh, in that thread you referenced timan, I found how to do history search with up/down arrow (as in if you type something before doing up/down arrow you get search and not just the last entry)
bindkey "^[[A" up-line-or-search ## up arrow for back-history-search bindkey "^[[B" down-line-or-search ## down arrow for fwd-history-search Also in that thread, got fink to work by using: [ -f /sw/bin/init.sh ] && source /sw/bin/init.sh I guess all I need now is to get a nicer prompt, resolve the .zshenv:3: no matches found: /usr/share/zsh/site-functions/*(:t) error and I'll be set. Thanks all for your help so far. V |
Found another problem:
Even though I have: PATH=$HOME/bin:/usr/local/bin:/usr/local/lib:/usr/bin:/bin:/usr/X11R6/lib:/usr/X11R6/include/X11:/usr/local/sbin:/usr/sbin:/sbin:/usr/lib:/X11R6/bin:/Developer/Tools export PATH MANPATH=/usr/share/man:/usr/bin/man:/usr/local/man:/usr/local/share/man:/usr/X11/man:/usr/man:~/man export MANPATH In my .zshenv file, It can't find the mysql command. In tcsh: % which mysql /usr/local/bin/mysql But in zsh: % which mysql mysql not found Something tells me it ain't loading from the .zshenv file, because: % echo $PATH /sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/Developer/Tools:/usr/X11R6/bin V |
vonleigh, it sounds like you're executing zsh by typing 'zsh', which will execute a subshell--that's why you get the (2) in the prompt if you're using my prompt. After making changes to .zshrc or .zshenv, open a new term window, and try typing 'exec zsh'. This will launch zsh, but it won't be a sub-shell of tcsh. To get back to tcsh, simply type 'exec tcsh'. I'm not sure what's going on with your $PATH yet. Regarding the functions error, did you include the two lines above
autoload -U +X ${fpath[1]}/*(:t) from my .zshenv? In other words, try this: zdotdir=$HOME fpath=($zdotdir/.zfuncs $fpath) autoload -U +X ${fpath[1]}/*(:t) Really, the default location of zdotdir will be $HOME, but it never hurts to put that in anyway just to be safe. |
Quote:
to fully exercise your zsh startup, try: % zsh -l # or --login, to get a login shell |
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 -athanks, V |
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/
|
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 "$*" | moreCode:
ll () {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 |
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...) |
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' |
Quote:
--the "obtuse comment fruitbat" |
Aha, it's because I had --color=auto set, instead of just --color. Thanks merv ;)
|
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. |
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:
%screenOh, 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 lsCode:
% cat .zshenv | fold -60Code:
% cat .zshrc | fold -60 |
Substitute
Code:
ls -lag "$*" | moreCode:
ls -lag $* | more |
Santin,
Perfect! It works now, thanks alot. Any ideas on the screen issue though? Also, I found something new: Code:
% sudo -sEdit: 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 |
Nothing about screen... yet.
However, here you have what you wanted for sudo Code:
% commandAs 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=..;..://'` |
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 |
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...:o Hasta mañana! |
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 |
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 Code:
{05:36 PM Code:
{05:36 PM 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] |
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 ;-) |
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 :) |
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 |
Hello,
Oh, I wasn't sure if that (2) was an error or not, but now it makes perfect sense. I'll keep it because it's a good idea, just didn't understand the logic of it originally. I'll be sure to read through the manpages to learn a bit more. Oh, and I fixed the .zprofile, just put the whole path in /sw/bin/fortune -a, duh :) Wohoo! it works, everything works! (knocks on wood). Now to the fun stuff, anyone else care to share their favorite tips and tricks? BTW paul, that lc is great! good visual indicator of what is a file and what is a folder very quickly. v |
vonleigh,
Asi que de Venezuela, que lindo pais, linda gente y linda música. Parece que despacito, vamos descubriendo que en este foro se habla español tambien. Saludos... |
There you go, a little tip...
Use zmv to change the name of multiple files and several other things (using globbing); say you have a folder with files without an extension and you want to give them all the same extension... (this reminds me of something see this thread), then all you have to do is Code:
% zmv '(*)' '$1.mp3'If you want to see what it will do before really executing the command use zmv -n. I find it particularly useful for creating multiple symbolic links in one step (for example in my QTSS movies folder...) Of course, the function must be autoloaded first Code:
% autoload -U zmvUn saludo para todos. |
Hi Vonleigh,
good to hear that things are finally approaching equilibrium (and thanks for the kind words re "lc"). I've not got a lot to offer re functions and the like, but the following options do help make zsh fun for me. setopt AUTO_CD # if nothing else matches go to named directory [[This is quite cool: "~" to go home "/" to go to root etc etc, and it picks up the cdpath as well, so if you have a directory called "src" in your home directory you get there from anywhere with a simple "src" (as long as there's not a directory of that name in your current working directory, or a command with that name). A nice piece of sloppiness that you soon miss when working in tcsh. Renders aliases like ".." being expanded into "cd .." and so forth utterly redundant. That one becomes a simple side-effect of the AUTO_CD option. To be fair, you do occasionally have a 1-2 second head-scratch when auto-completing something (a command, mostly), until you realise that there's a candidate directory that's making multiple matches where you think there's only one. A minor growing pain!]] setopt EXTENDED_GLOB # much better brand of regexp setopt NO_HUP # don't throw away background jobs when quitting unsetopt promptcr # don't let the prompt overwrite output [[to my mind these just make zsh do the right things at the right time. Maybe they're contained above, I haven't checked carefully.]] Cheers, Paul |
Quote:
This is the best way to go as you will get that shell when logging in remotely or starting up a terminal in XDarwin/OroborOSX. dan |
I agree dboy, Netinfo is the best way to set the default shell.
Tip: Not zsh related, but cool: use w3m (fink install w3m) to quickly browse the web (I am in a dial-up connection, so speed matters), then when you get to an interesting page hit 'M' and it will open in your default browser. Additionally you can use w3m as a pager or to view man pages (w3mman). As always, take a look at the manpage for more info: Code:
% w3mman w3m |
Hello,
Sao, gracias por tus lindas palabras. De verdad extraño mi país y mi gente muchísimo al estar ahora en California estudiando. Que risa que todo el mundo habla español. Santin, the zmv is a great tip, thnx for sharing. Paul, Auto_CD is really good, I have taken out my .. to cd .. alias and have this instead, much better. Do you think you could explain a bit better what you mean by "better brand of regexp?" for extended glob? The others sound pretty reasonable and have added them, even though I'm not exactly sure what promptctr does. dboy, I have set it in Netinfo. If you read the thread you'll see that that is what solved my problem of sudo -s and screen dropping me in a tcsh shell. Now it seems pretty obvious, but for a while I wasn't sure what was going on. I didn't do it there first because I didn't want to commit to zsh until I had ironed out the kinks. Santin, I'll check out w3m, sounds good as I have been known to browse the web with links, just because it's quicker. Great tips guys! Hopefully we'll get more obscure ones so that you guys get something out of this thread too. :) v |
Hi again,
re EXTENDED_GLOB : zsh has some really nice globbing capabilities, but their capacity to confuse has led to a very restricted set of symbols being interpreted as "special" by default. For example, the use of "^" as an exclusion operator (ie, match everything *except* what's after the hat), the use of "~" as a "this and not that" (ie, match what's on the left of the tilde as long as it doesn't match what's on the right). There are others as well, but that'll do for now. If you routinely use these symbols in filenames the EXTENDED_GLOB option might trip you up on occasion, but for me the extra matching options are a welcome feature. I'm pretty sure we had a thread winding through some of these aspects relatively recently, so let's have a look... well there's a few bits and pieces about globbing here: http://forums.macosxhints.com/showth...&highlight=zsh and there's a very brief thread about extended globbing bits and pieces here: http://forums.macosxhints.com/showth...&threadid=6837 The unsetopt promptcr simply ensures that the rewriting of the prompt doesn't overwrite any screen output that you might have drawn (without a trailing carriage return). For example: ~ % setopt promptcr ~ % echo -n "Enter a number:" ~ % unsetopt promptcr ~ % echo -n "Enter a number:" Enter a number:~ % Unsurprisingly, I definitely prefer the latter behaviour. Seems that promptcr is "set" by default in order for people to be able to use fancy RHS-of-the-screen prompts. That ain't happenin' 'round here in a hurry! Cheers, Paul |
bash_completion
I just want to remind you people of the bash_completion project. It gives almost all *nix commands a reasonable completion default. Like ./configure, ssh, man, gzip ... you name it, bash_completion has it. Just put the bash_completion file in /etc and put simething like this in your /etc/bashrc:
Code:
. /etc/bash_completionhttp://www.caliban.org/bash/ |
|
| All times are GMT -5. The time now is 06:13 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.