maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   .zshrc for N900 (updated, now works for me[tm]) (https://talk.maemo.org/showthread.php?t=68685)

avx 2011-01-20 18:44

.zshrc for N900 (updated, now works for me[tm])
 
// couldn't find a better place, move/merge if needed.

Update: now works flawless for me. Guide is rewritten from the original.

There's still a chance to brick the device, but not permanently, so reflashing is possible. You've been warned, you'd better have a backup.

A .deb would be really useful, if you're capable of doing so, please don't hesitate :)

--

I made some modifications to my desktop's .zshrc to better fit (my) needs on the N900:
  • more efficient use of the screenspace
  • a lot less typing needed
  • some useful functions
  • files directly linked to apps(i.e. './movie.avi' loads it in mplayer, ...)
  • workaround for some hard to press keys(at least on my layout[de])
  • ...

I'd like to share this with you, so maybe someone else can benefit and I'd be glad to receive patches(diffs) or additions.

Getting started:

a) you need to be able to become root

b) you need extras-{devel,testing} both enabled

c) open the terminal
d) become root
e) fetch this file: http://phorcix.org/proj/n900/conf/zsh-setup
f) run
Code:

sh /path/to/zsh-setup
The script first tests, if wget and libncursesw5 are already installed, if not, it apt-gets both of them. After that, it downloads and extracts the tarball containing zsh. Then it makes the needed chmod/chown to get compinit working, downloads the config- and env-files and finally changes the default shell to zsh for the user-account (if you also want it for root, uncomment the corresponding line - risky!).

When all this is done, have a quick look over the command's output and make sure, there are no errors. If everything looks ok, reboot the device.
Note:ZSHs first start will take a relatively long time, since it's building the entries needed for autocompletion. This is one time only, so after that, it shouldn't be slow at all.

--

A little overview of what's possible with it - please forgive me, if I use zsh-terms too often...

a) auto_cd is on, thus
Code:

cd /some/path
now also simply works as
Code:

/some/path
b) some named-directories are setup, thus
Code:

cd ~cam
changes the directory to '/home/user/MyDocs/DCIM/'
of course
Code:

cp somefile ~cam/
also works

some other named-dirs are also setup, namely for the paths of documents, sounds, images, videos, backups and some more

c) shortcuts for things like apt-get are setup, thus i.e.
Code:

agi nc
autocompletes. Same for apt-get {auto}remove/purge, apt-cache search, etc.

d) ' P ' works as ' | '

e) easy layout switching, in my case de<->dvorak

f) '+'/'-' to turn up/down the volume

g) easy 'chmod'/'chown', ie '755 file'

h) shortcuts for a lot of commands, i.e. A,E,G,L -> awk,echo,grep,less and more

i) associations for most commonly used files, espacially media is assigned to mplayer

j) setup to 55 colums, so its easily editable on the N900 in vim with 'set number'

--

Love, praise, thoughts, critics, deathwishes are welcome.

In the hope that someone finds it useful, cheers,
avx

PS: a little screeny of what my setup looks like, can be found in this post

Char 2011-01-21 18:28

Re: .zshrc for N900
 
thank you, this is great
edit: damn, had to reflash too :(

avx 2011-01-22 20:02

Re: .zshrc for N900
 
Quote:

Originally Posted by Char (Post 925602)
edit: damn, had to reflash too :(

Sorry for that, hope you didn't loose too much data of value.

I'm looking into this, I guess the init-scripts are borked, but I'm not sure, yet.

epitaph 2011-01-22 20:07

Re: .zshrc for N900
 
Could u please make a .deb package?

avx 2011-01-22 20:30

Re: .zshrc for N900
 
Quote:

Originally Posted by epitaph (Post 926314)
Could u please make a .deb package?

For what, the config?

Maybe I could, but I'd need to read up on it, since I'm more of the .ebuild guy ;)

Char 2011-01-23 10:07

Re: .zshrc for N900
 
Quote:

Originally Posted by avx (Post 926311)
Sorry for that, hope you didn't loose too much data of value.

I'm looking into this, I guess the init-scripts are borked, but I'm not sure, yet.

emmc was saved and my latest backup was recent enough so all's good

do hope you figure out how to get it running properly though! :)

BernardB 2011-01-23 16:44

Re: .zshrc for N900
 
The bricking issue appears to be that zsh is used to execute /etc/X11/Xsession at startup. The output of run-parts in that script is delimited by newlines, which ash and bash recognise as field separators and split appropriately when it is used in the following for loop. Zsh isn't splitting at newlines and tries to execute the entire output of run-parts as one command.

Does somebody who's willing to risk bricking their phone want to try adding this line to your /home/user/.profile ? It shouldn't brick it :) It should get busybox to run zsh in xterms and ssh sessions.

Code:

[ -n "$PS1" ] && [ "$0" != "/etc/X11/Xsession" ] && exec /bin/zsh "$@" || :
Make sure it's all on one line. Spelt out, it says "if I am an interactive shell, and I'm not running the Xsession script, then run zsh instead, otherwise return 0"

I'm 99% confident that it will do the right thing(tm), but not confident enough to try it myself before I board a plane in a few hours. Please forgive my sensibility :)

avx 2011-01-23 16:51

Re: .zshrc for N900
 
Thanks, BernardB, will try that later tonight.

Also thanks for the hint on Xsession, I'll have a look at that, too and hopefully found a solution.

BernardB 2011-01-23 16:52

Re: .zshrc for N900
 
Oh, what may also work (and be slightly more efficient as it avoids starting two shells each time), is to set zsh as your default shell, but to add this line to your .zshenv file:

Code:

[ "$0" = "/etc/X11/Xsession" ] && emulate sh || :
I checked that it allows Xsession to run correctly, but I still haven't been game to boot my phone with it like that. Wouldn't mind confirmation of that either :)

avx 2011-01-23 17:22

Re: .zshrc for N900
 
Does anyone of you know, if/how I could get access when it stops at the moving balls? Either drop me into a shell or connect to my wlan and enable ssh?

avx 2011-01-23 17:50

Re: .zshrc for N900
 
Ok, I think I've got some kind of little breakthrough.

I did 'chsh -s /bin/zsh' for both user & root, run 'sed -i "s@/bin/sh@/bin/zsh@"' on everything in /etc/X11/* and put your command in .zshenv of both user & root. Rebooted and it booted straight up, and 'echo $SHELL' reports zsh for both users.

The one thing I left out right now, is the chmod&chown-part described above, to properly use compinit.

So I'll create a backup now and see if maybe the chown/chmod is causing the havoc.

Edit, holy hell, it still works.

Edit2, I also added 'PATH=/sbin:/bin/:...' to the .zshrc of root, since that didn't get set correctly and somehow only had /usr/{sbin} in it, so that could have been the problem, too.

Edit3, for now I'm happy, I'll do a backup, grab something to eat, do a full reflash and if it works again, rewrite the guide. Thanks for the hints so far :)

Edit4, if someone with more knowledge of Debian internals knows how to make a .deb out of this, a simple guide or a working .deb itself would be nice. Thanks.

Snark1994 2011-01-23 20:43

Re: .zshrc for N900
 
Guys, thankyou so much for this. I panicked when I killed my phone doing this, eventually reflashed. I then had a look on the 'net for "n900 zsh" and found this, and followed it successfully :) and only then noticed it was dated today! I registered to say thanks, and I'm happy to try to create a .deb if people want :)

avx 2011-01-23 21:10

Re: .zshrc for N900
 
Welcome to the forums, Snark1994 :)

I'm currently writing a zsh-setup script, which automates the steps I've taken, so that'll get a little easier. Of course, a .deb would be really appreciated, so it could go easier to -testing/devel if it works.

BernardB 2011-01-23 21:19

Re: .zshrc for N900
 
Quote:

Originally Posted by avx (Post 926840)
run 'sed -i "s@/bin/sh@/bin/zsh@"' on everything in /etc/X11/*

Curious - why is that needed? That bit's just a bit scary as it's not particularly upgrade-proof.

Awesome that it worked though.

I also wouldn't recommend changing it for root. A lot of scripts (e.g. package install scripts) expect the default shell to be bash or ash. For root you could use the .profile exec /bin/zsh trick.

avx 2011-01-23 21:55

Re: .zshrc for N900
 
Dunno why/if it's needed to run the sed-stuff, I just happened to try it and it worked and I didn't yet try it without it.

As for root, I consider your argument as valid, but imho the packages are broken, if they rely on bashisms or other non-standard stuff.

Anyway, I finished the setup-script, will reflash the phone and try it now, wish me luck :p

Edit, #commented out the change for root and left a note.

BernardB 2011-01-23 21:57

Re: .zshrc for N900
 
Quote:

Originally Posted by avx (Post 926973)
As for root, I consider your argument as valid, but imho the packages are broken, if they rely on bashisms or other non-standard stuff.

Well actually the problem is that zsh is incompatible with sh/bash by default. If zsh is invoked as sh/bash, then it goes into sh/bash-compatibility mode, but by changing the #! line, you're telling zsh that it doesn't need to.

Anyway, good luck!

avx 2011-01-23 22:22

Re: .zshrc for N900
 
So, got it working, tried two times incl. complete vanilla+rootfs flashing, both times success. I'll go and update the first post.

BernardB 2011-01-23 22:34

Re: .zshrc for N900
 
Awesome. Cheers!

Snark1994 2011-01-24 22:20

Re: .zshrc for N900 (updated, now works for me[tm])
 
If you've already got a .sh script, then this seems to describe a variety of methods + packages for making it into a .deb :)

avx 2011-01-25 17:54

Re: .zshrc for N900 (updated, now works for me[tm])
 
Quote:

Originally Posted by Snark1994 (Post 927710)
If you've already got a .sh script, then this seems to describe a variety of methods + packages for making it into a .deb :)

Thanks, will have a look at it. Might take some time, though, since I'm currently working on backup-solution better fitting my needs(multi-{parallel}-hosts, encryption, easy replay of single files, ...).

cheers,
avx

Char 2011-02-24 14:50

Re: .zshrc for N900 (updated, now works for me[tm])
 
A safer way of doing this would be to change the XTerm launch script to run "osso-xterm /bin/zsh". That way you're nowhere near risking a brick. I'm not taking any more risks after I bricked the first time, so this is how I have it running right now (with the default shell set as sh) and I have no problem. Thanks a lot, zsh makes using the terminal way less of a pain :P

robotanarchy 2013-05-18 16:33

Re: .zshrc for N900 (updated, now works for me[tm])
 
Thanks for the guide, avx. I'm happily using zsh now with grml's config (however, you'll want to delete everything with "limit" in the config, as it produces a warning, and also "ls", because it calls the busybox with wrong parameters).

Oh and I also almost bricked the phone... good to have the recovery console installed :) I've then changed the shell back to /bin/sh in /etc/passwd :)

I recommend that you don't set the shell for any user by default. Let the user do this, if he thinks that he's ready.

I'll go with Char's solution to change the launcher. /bin/zsh can also be set in PuTTY as start command, in case anyone uses that too :)



EDIT: works great now! I've added some aliases, so I'll always have zsh instead of bash (you might need to customize that if you use gainroot, I don't):


/home/user/.zshrc.local
alias su="sudo su -c /bin/zsh"
/root/.zshrc.local
alias suu="su user -c /bin/zsh"

antifarben 2013-07-04 20:39

Re: .zshrc for N900 (updated, now works for me[tm])
 
Did you use the zsh binaries from http://talk.maemo.org//showthread.php?p=1356894
?


All times are GMT. The time now is 22:15.

vBulletin® Version 3.8.8