×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Linux Advent Calendar: "24 Outstanding ZSH Gems"

samzenpus posted more than 2 years ago | from the where's-the-candy? dept.

Christmas Cheer 46

First time submitter Manko10 writes "After the Advent series last year, there is again a Linux Advent calender. The topic of this year's Advent series is '24 Outstanding ZSH Gems'. Every day from December 1st until December 24th an article will be published each covering a special feature of the Z Shell you might not have known yet."

cancel ×
This is a preview of your comment

No Comment Title Entered

Anonymous Coward 1 minute ago

No Comment Entered

46 comments

Only 24 features? (3, Interesting)

Baloroth (2370816) | more than 2 years ago | (#38233260)

Well, that'll get you through... what, the first page of the manual?

The damn thing has a built-in tcp command system (ok, I think it's technically a "module"). The main man page is just a redirect page. Hell, it might even rival emacs for complexity. I know, I didn't think it was possible either...

Re:Only 24 features? (0)

Anonymous Coward | more than 2 years ago | (#38233680)

so does bash.

exec 5/dev/tcp/www.google.com/80
echo -e "GET / HTTP/1.1\n\n" >&5
cat &5

Re:Only 24 features? (2)

ArsenneLupin (766289) | more than 2 years ago | (#38243588)

Slashdot eats < signs for breakfast.

Here is a fixed version:

exec 5<>/dev/tcp/www.google.com/80
echo -e "GET / HTTP/1.1\n\n" >&5
cat <&5

Preview is your friend!

Re:Only 24 features? (2)

inglorion_on_the_net (1965514) | more than 2 years ago | (#38235794)

Hell, it might even rival emacs for complexity. I know, I didn't think it was possible either...

It's not so strange if you think about it. Both are operating systems cleverly disguised as applications, complete with their own programming languages.

The major difference is that zsh is disguised as a shell, and Emacs is disguised as a text editor.

I, for one, look forward to the arrival of our minor-mode-wielding zsh overlords.

<3 zsh (3, Informative)

mirix (1649853) | more than 2 years ago | (#38233300)

I wasn't familiar with zsh until I used grml [grml.org] (a fairly handy debian-based live distro, I use for fixing things on occasion). It comes with a pretty spiffy zshrc and zsh by default, which opened me to some of the features of it... pretty nifty... Now I use zsh on everything.

Some info about grml's use of zsh, here [grml.org].

Re:3 zsh (1)

EvanED (569694) | more than 2 years ago | (#38233476)

I started using zsh the instant I read about ** globs.

Bash has them now, but I see little reason to switch back.

Re:3 zsh (1)

Baloroth (2370816) | more than 2 years ago | (#38233600)

Yep, I too strongly recommend zsh. The command line completion especially is far, far better than bash. Although you pretty much have to create (or download: there are quite a few good ones online) an extensive zshrc file to use it properly. Thanks for pointing out grml, I might have to look into using that in the future.

Re:3 zsh (0)

Anonymous Coward | more than 2 years ago | (#38238174)

For some reason which I don't really understand, my .zshrc [blissett.me.uk] is the top hit on Google UK for "zshrc".

It doesn't have anything amazing, but some of it is useful to know about (from zstyle onwards, mostly).

Re:3 zsh (0)

Anonymous Coward | more than 2 years ago | (#38238594)

There's also https://github.com/robbyrussell/oh-my-zsh that adds some nice features, and has a really active community.

Not a ZSH gem, but... (5, Funny)

serviscope_minor (664417) | more than 2 years ago | (#38233612)

Not a ZSH gem, but this is probably the last word in BASH prompts.

PS1='C:$(echo ${PWD//\//\\\} | tr "[:lower:]" "[:upper:]" |
                          sed -e"s/\\([^\\]\\{6\\}\\)[^\\]\\{2,\\}/\\1~1/g" ) >'

you'd be wise not to trust random code, but if you look carefully it uses only echo, tr and sed, none of which have programmable IO and only piping, so it is safe.

Re:Not a ZSH gem, but... (5, Funny)

Anonymous Coward | more than 2 years ago | (#38233716)

You are evil.

Re:Not a ZSH gem, but... (1)

Anonymous Coward | more than 2 years ago | (#38233738)

+1 Nostalgia

Brings me back to 1996 when Windows was cool.

Re:Not a ZSH gem, but... (1)

Anonymous Coward | more than 2 years ago | (#38233962)

I feel ... unclean ...

Re:Not a ZSH gem, but... (0)

Anonymous Coward | more than 2 years ago | (#38235872)

Reminds of an old (like '98) book about Linux that's still somewhere in my University's library - the blurb on the back was "Friends don't let friends use DOS"

Re:Not a ZSH gem, but... (2)

Kagetsuki (1620613) | more than 2 years ago | (#38234092)

I like how you even used sed to switch up the slashes and break down long names. Now to sneak this into someones bashrc and catch their face when they login...

Re:Not a ZSH gem, but... (0)

Anonymous Coward | more than 2 years ago | (#38234360)

root will be doing this to everyone's .bashrc via cron on April 1 from now on.

Re:Not a ZSH gem, but... (0)

Anonymous Coward | more than 2 years ago | (#38234116)

I chuckled a bit, not gonna lie.

Re:Not a ZSH gem, but... (0)

Anonymous Coward | more than 2 years ago | (#38234184)

That is absolutely hilarious.
It may very well be worthwhile "incorporating" this into someone's account just for the shocked expression that will occur

Re:Not a ZSH gem, but... (1)

tqk (413719) | more than 2 years ago | (#38234392)

I don't get it:
PS1='C:$(echo ${PWD//\//\\\} | tr "[:lower:]" "[:upper:]" | sed -e"s/\\([^\\]\\{6\\}\\)[^\\]\\{2,\\}/\\1~1/g" ) >' xterm
I got a regular xterm with my regular PS1 prompt. Whoosh?!?

Aside, I liked both zsh and grml when I used them, but decided neither were necessary and not for me. Besides, unless you're a shell programmer wizard, you're not going to see a lot of differences between bash, ksh, and zsh. They all pretty much function the same at a user level. Well, except for the resources that zsh sucks up, that is.

Re:Not a ZSH gem, but... (3, Informative)

CronoCloud (590650) | more than 2 years ago | (#38234814)

You should have got a Windows style C:prompt, including truncated directroy names if they were over 8 characters.

Try an "export" before the command, and see if that helps

Re:Not a ZSH gem, but... (0)

Anonymous Coward | more than 2 years ago | (#38234830)

It basically makes the prompt look like a dos prompt. Your .whateverrc is probably resetting PS1. Run it without the xterm.

Re:Not a ZSH gem, but... (0)

Anonymous Coward | more than 2 years ago | (#38234866)

When you do it that way, you get your regular prompt because the new shell will execute .bashrc which is going to override the PS1 you just set. Just try setting PS1 in a shell *without* running a command in the same line, and you will see it take effect immediately.

Re:Not a ZSH gem, but... (1)

tlhIngan (30335) | more than 2 years ago | (#38234970)

you'd be wise not to trust random code, but if you look carefully it uses only echo, tr and sed, none of which have programmable IO and only piping, so it is safe.

Funny enough, I sorta figured out what it did by careful inspection of the line.

So PS1 gets set to "C:", then the current working directory. Hrm... then TR is used to change all lowercase to upper case, followed by a very peculiar sed. All the while it seems the / are being replaced with \ (\\ for the escaping).

Since the word "evil" was attached to it, well, there could only really be one trick evil enough to do on a UN*X user... especially one involving the command prompt line.

It might be nice to get rid of the space between the directory and the > though. It is C:\>, not C:\ >.

Re:Not a ZSH gem, but... (0)

Anonymous Coward | more than 2 years ago | (#38236168)

I'd love to get a version of this that works in ksh :)

Z Shell (1)

Trogre (513942) | more than 2 years ago | (#38234154)

Here's a gem:

In my country Shell petrol stations have recently re-branded as: Z

Co-incidence? I think not.

perl (0)

Anonymous Coward | more than 2 years ago | (#38234652)

Who does major shell programming, when they can use perl instead?

Re:perl (0)

Anonymous Coward | more than 2 years ago | (#38234690)

Who uses perl programing when they can use python instead?

Re:perl (1)

leaen (987954) | more than 2 years ago | (#38235414)

Who uses python programming if they can use ruby instead?

Re:perl (0)

Anonymous Coward | more than 2 years ago | (#38236092)

Who uses ruby programming if they can use unicon instead?

Re:perl (0)

Anonymous Coward | more than 2 years ago | (#38239784)

Who uses lisp programming if they can use lisp instead?

(Get it?)

Re:perl (-1)

Anonymous Coward | more than 2 years ago | (#38236370)

Ruby is not in the same class as the other two. Perl is like Brainfuck, an indecipherable mumbo-jumbo of special characters, and Python is like Whitespace, a language where the space and tab characters are part of the language.

Ruby, on the other hand, is a real language.

Re:perl (0)

Anonymous Coward | more than 2 years ago | (#38236742)

Who uses ruby programming when they can use zsh?

Re:perl (1)

Hatta (162192) | more than 2 years ago | (#38237066)

The great thing about ZSH, is that it greatly expands what you can actually do, without crossing the line into "major shell programming". These are one or two liners here, if you were using Bash you might rightly choose Perl for this stuff, but not if you use ZSH.

Why zsh instead of bash? (1)

CronoCloud (590650) | more than 2 years ago | (#38234808)

Maybe I'm ill informed since I've only run "Redhatty" distros (SCEfoos wacky Kondara-ized RH6 on the PS2, YDL, and now Fedora) but isn't bash the standard shell for Linux? So wouldn't bash tricks be more useful?

Re:Why zsh instead of bash? (0)

Anonymous Coward | more than 2 years ago | (#38235158)

I thaught bash was only installed by default as an excercise to get a real shell.

Re:Why zsh instead of bash? (1)

inglorion_on_the_net (1965514) | more than 2 years ago | (#38235814)

I think the trick here is that people who think zsh is a better shell than bash are using this campaign to raise awareness of zsh.

By the way, I do think zsh is the better shell. Just to name one of the things I love about it: writing custom command completion for it is pretty easy (certainly compared to bash). I and other people have used this to provide tab completion for mostly anything you can think of, including things like command options and filenames on remote machines. Go check it out if you haven't already.

I'm being completely serious here... (1)

fotoguzzi (230256) | more than 2 years ago | (#38235506)

...I'm seeing a blog. Is there an Advent calendar [typepad.com] somewhere that I'm missing?

Re:I'm being completely serious here... (4, Informative)

bLanark (123342) | more than 2 years ago | (#38235870)

You are looking for something like this? [perladvent.org]

Re:I'm being completely serious here... (1)

fotoguzzi (230256) | more than 2 years ago | (#38235974)

Yeah! Thanks. I had never even heard of an Advent calendar until a year ago. I have not found when/why some of them have the dates out of sequence, but that's a separate question.

Re:I'm being completely serious here... (1)

bLanark (123342) | more than 2 years ago | (#38368232)

Well, the reason the dates are all mixed up is that it in the real world, it adds to a six year-olds excitement when he's searching for todays door, which has *candy* behind it.

Check for New Comments
Slashdot Account

Need an Account?

Forgot your password?

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>
Sign up for Slashdot Newsletters
Create a Slashdot Account

Loading...