Live data from Hacker News

Zsh is your friend.

mikegrouchy.com

101–110 of 117 posts

Re: Zsh is your friend.

#101
post #23

Is anybody else addicted to shell mode within emacs? I love having the shell as just another buffer right in the editor. Easy history searchability, copy and paste between code and various repls or SQL prompts, and all the other full editor features available at the prompt.

I like the idea, but I'm too used to bash's autocompletion (the Emacs-provided autocompletion is similar but not quite the same), the autocd option, CDPATH, etc. And changing directories in the shell with anything other than cd (pushd, or an alias or script) confuses Emacs's directory completion.

The last couple of days I've been trying terminal-mode rather than shell-mode, and it works much better. Many standard Emacs keybindings get remapped though.

Re: Zsh is your friend.

#102
post #38

While from what I have read about it zsh is a nice shell, it doesn't deal with what I find to be the biggest problem with bash, sh, and just about every shell that isn't fish: the horribly ugly and inconsistent syntax. And I think it's rather sad that on what is supposedly the most advanced shell of our generation, you still have to deal with a thousand ridiculous redirections and quoting styles, different delimiter…

Try Plan 9's "rc". It has a more C-like syntax, so you write things like "for (i in `{seq 1 100}) { echo $i }"; I really enjoy writing in rc.

One of my favourite aspects of rc is the sane array handling.

In bash: $array expands to the _first_ element of the array; you have to say ${array[@]} to get the whole array. And then you have to quote it in case one of the elements has spaces.

In rc: $array expands to the whole array, and the expansion is _not_ re-parsed, so if an element of the array has spaces in it, it is still considered a single element after the array variable expansion.

For this reason rc doesn't even need double-quoting; it only has single-quoting for escaping spaces in string literals.

Re: Zsh is your friend.

#103
post #48

Earlier quoted context omitted.

Zsh has knobs for shared history. You can configure all terminals to have the same history at the same time, but I have it set to add history to the .zsh_history file immediately, but each shell gets it's own history. So ctrl-r in a shell lists commands entered into that shell (or preexisting when it started), and opening a new terminal starts with the shared history from all terminals. This is really the best of bot…

im pretty sure bash does shared history if you desire it, the configuration is just not as directly obvious. I prefer a long histfile (unlimited really, i. think i have it set to a million lines, but im at about 70 000. i even keep it backed up regularly because its fairly easy to trash the histfile if you are opening subshells and do the wrongthing. timestamped, too, which i find really handy. that said, i do use an…

Bash configuration for shared history:

  # Append to ~/.bash_history instead of overwriting it -- this stops terminals
  # from overwriting one another's histories.
  shopt -s histappend
  # Only load the last 1000 lines from your ~/.bash_history -- if you need an
  # older entry, just grep that file.
  HISTSIZE=1000
  # Don't truncate ~/.bash_history -- keep all your history, ever.
  unset HISTFILESIZE
  # Add a timestamp to each history entry.
  HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S  "
  # Don't remember trivial 1- and 2-letter commands.
  HISTIGNORE=?:??
  # What it says.
  HISTCONTROL=ignoredups
  # Save each history entry immediately (protects against terminal crashes/
  # disconnections, and interleaves commands from multiple terminals in correct
  # chronological order).
  PROMPT_COMMAND="history -a; $PROMPT_COMMAND"

Re: Zsh is your friend.

#104
post #6

While from what I have read about it zsh is a nice shell, it doesn't deal with what I find to be the biggest problem with bash, sh, and just about every shell that isn't fish: the horribly ugly and inconsistent syntax. And I think it's rather sad that on what is supposedly the most advanced shell of our generation, you still have to deal with a thousand ridiculous redirections and quoting styles, different delimiter…

Once you learn the zen of shell script, like any programming language, those problems pretty much go away. Shell script is a tiny language packed with features and can be learned through constant use in a week, but like any language, it takes time to master. It's incredibly powerful for interactive use and data manipulation combined with the standard Unix tools and sometimes pulling out perl or python is more work th…

Maybe you should do some lessons on this on any of the e-learning sites? I bet a lot of people would pay $25 or whatever for that.

Re: Zsh is your friend.

#105
post #77
post #56

If you're looking for the "keyboard navigable completion list", this what you want: zstyle ':completion:*' menu select

I tried that and about a million other things in Ubuntu. When I hit tab I see options, but nothing I put in my .zshrc will allow me to use the arrow keys or anything else to navigate the completion list. I am using oh my zsh but I tried turning it off and it didn't seem to matter. Maybe only Mac users use zsh?

With the default oh-my-zsh config, you have to hit tab two times, for example ls

Re: Zsh is your friend.

#106
post #42
post #38

Earlier quoted context omitted.

Try Plan 9's "rc". It has a more C-like syntax, so you write things like "for (i in `{seq 1 100}) { echo $i }"; I really enjoy writing in rc.

How is that better than bash or zsh: for i in `seq 1 100`; do echo $i; done zsh: for i in `seq 1 100`; echo $i

The rc example is worse than the first of yours. I hate the zsh special syntax in the second: it violates a deeply ingrained code feel I have about the syntax of shell code. The do ... done syntax helps the eye.

rc really shines when you have problems that in bash or zsh would suggest using multiple layers of expansion. The semantics of rc's expansion is much less thorny.

I prefer real examples - here, why not just write

    seq 1 100
- what is the loop for? And shell loops can frequently (always, if you are willing to write helper scripts) be replaced with xargs, which tends to be very much faster, e.g.

    seq 1 100 |  xargs echo
(which doesn't quite give the same output, but passing -n1 to xargs fixes that)

Re: Zsh is your friend.

#107
post #61

Earlier quoted context omitted.

I feel that the days of a shell being used for scripting are past. I've noticed this attitude among those who tend to use sysadmin-minimizing features of the internet, such as cloud hosting. There's still a whole world of real server out there, though.

That is true. I do minimal system administration, so that is not a concern for me. I tend to use a shell for system interaction more than scripting. In that regard, I give more importance to interactivity enhancements. On the other hand, I have found myself using bash to automate simple things in our company testbed. As soon as I need a datastructure more than an array, or recursive functions, I jump to lua. If your…

I disagree. As a programmer I can represent inputs and outputs as text and write code to do intended transformations. As a quick ad hoc test I can easily knock up a shell pipeline to give confidence in those results, even if it would be too slow for production. There's many occasions when powerful shell usage is quicker to write than Python, etc.

My comment in reply to http://www.iheartchaos.com/post/16393143676/fun-with-math-di... is one example.

Re: Zsh is your friend.

#108
post #23

Is anybody else addicted to shell mode within emacs? I love having the shell as just another buffer right in the editor. Easy history searchability, copy and paste between code and various repls or SQL prompts, and all the other full editor features available at the prompt.

I like the idea, but I'm too used to bash's autocompletion (the Emacs-provided autocompletion is similar but not quite the same), the autocd option, CDPATH, etc. And changing directories in the shell with anything other than cd (pushd, or an alias or script) confuses Emacs's directory completion. The last couple of days I've been trying terminal-mode rather than shell-mode, and it works much better. Many standard Ema…

Edit: I meant term-mode (M-x term), not terminal-mode (M-x terminal-emulator). No idea why there are two different terminal emulators in Emacs, but 'M-x term' seems the better of the two, or at least the keybindings make more sense to me.

There is also 'M-x serial-term' should you ever need it.

Re: Zsh is your friend.

#109

Earlier quoted context omitted.

I have been using fish for several years now. It's community is a fraction of zsh, bash, and others, and I've tried to go back to them, mostly out of misplaced "everyone else is doing it" mindset Fish is a great shell. It's a modern shell, that uses colors, UTF, and processing power that didn't exist when the others were designed. I feel the best thing about it is the sane defaults and large number of prebuilt comple…

I tried out fish a month back, but got stuck on 2 things, one which i use frequently. 1. I use the Alt-. (dot) to get last argument of previous command. 2. Getting output of previous command such as : `!!` (backtick !! backtick) for which I get a "no such file". I asked on reddit, but got no replies. Thx.

!! is not specific to fish. It is a history feature to get the last command. It's like using '!ec' for getting the last command that starts with 'ec'. Using `!!` is not "getting output of previous command", it is re-executing it and getting that output.

For that alt+. tip, I'd use the special $_ var.

Re: Zsh is your friend.

#110

Earlier quoted context omitted.

I like the idea, but I'm too used to bash's autocompletion (the Emacs-provided autocompletion is similar but not quite the same), the autocd option, CDPATH, etc. And changing directories in the shell with anything other than cd (pushd, or an alias or script) confuses Emacs's directory completion. The last couple of days I've been trying terminal-mode rather than shell-mode, and it works much better. Many standard Ema…

Edit: I meant term-mode (M-x term), not terminal-mode (M-x terminal-emulator). No idea why there are two different terminal emulators in Emacs, but 'M-x term' seems the better of the two, or at least the keybindings make more sense to me. There is also 'M-x serial-term' should you ever need it.

There are M-x shell and M-x eshell to run shells within emacs.

See http://www.masteringemacs.org/articles/2010/11/01/running-sh... for comparison.

Post reply on HN