Live data from Hacker News

Unix Tricks

cfenollosa.com

71–80 of 166 posts

Re: Unix Tricks

#71

You know what I hate? My history isn't aggregated in real time across all my Mac OS X terminal windows. You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly. Especially when I hit the up arrow to go back in my terminal history.

>You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly. Are you escaping your color codes in PS1 correctly? Bad: PS1="\033[1;32m \w \033[m $" Good (notice the extra \[ and \]): PS1="\[\033[1;32m\] \w \[\033[m\] $"

Mine seems escaped as hell, but still gets wrapped. Anything I'm missing?

edit: couldn't get UTF-8 branch symbol to be properly displayed here, but this is how it looks:

http://i.imgur.com/zuq24gV.png?1

  function fancyPrompt {

   local bgBlue="\[\033[48;5;31m\]"
   local fgBlue="\[\033[38;5;31m\]"

   local fgWhite="\[\033[38;5;231m\]"

   local bgDarkBlue="\[\033[48;5;24m\]"
   local fgDarkBlue="\[\033[38;5;24m\]"

   local bgDarkGray="\[\033[48;5;237m\]"
   local bgLightGray="\[\033[48;5;245m\]"
   local fgLightGray="\[\033[38;5;245m\]"
   local colorClear="\[\033[0m"

   local branch
   local branch_symbol="\[\] "

   if branch=$( { git symbolic-ref --quiet HEAD || git rev-parse --short HEAD; } 2>/dev/null ); then
   	branch=${branch##*/}
   	export PS1="${bgBlue}${fgWhite}\h${colorClear}${fgBlue}${bgDarkBlue}\[\] ${fgWhite}\w${bgLightGray}${fgDarkBlue}\[\] ${fgWhite}${branch_symbol}${branch}${fgLightGray}${bgDarkGray}\[\] ${colorClear}"
   else
   	export PS1="${bgBlue}${fgWhite}\h${colorClear}${fgBlue}${bgDarkBlue}\[\] ${fgWhite}\w${bgDarkGray}${fgDarkBlue}\[\] ${colorClear}"
   fi

 }

Re: Unix Tricks

#72
post #55
post #28

Earlier quoted context omitted.

> You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly. Yeah, keeping ctrl pressed in and pressing x followed by e (CTRL + x e) will open up the current line in $EDITOR and when you edit and save, replaces the current line with what you entered in your editor. Really a killer feature.

In Linux with bash (and probably other shells that are bash-compatible), you can use vi to edit any of the commands in your command history, and then execute the edited version. Do this at the command prompt, or once in your ~/.bash_profile to make it permanent: set -o vi After that, you can search for any of the commands in your history, edit it, and then execute the edited command, by doing this: At the prompt, typ…

Or emacs.

The 'set -o ' bit sets the readline editing environment to be similar to vi. It can be set to emacs.

C-xC-e (edit-and-execute-command) invokes the editor specified by $VISUAL, $EDITOR, or emacs, in that order. You could set it to scrivner if you wanted to (though I'm not sure that would necessarily work on exit).

I've tested with VISUAL set to nedit, from which I then changed it to uptime. Now I get loadavg when I want to edit my command line ;-)

Re: Unix Tricks

#73

Earlier quoted context omitted.

I love fish and have happily been using it for years. Every time it comes up here, though, someone inevitably will complain about compatibility - and I will admit that RVM, for instance, has definitely caused me problems with fish in the past. I guess it depends quite a lot on your particular usage and requirements.

I never got RVM working with fish; unsurprising, seeing as it’s 20k lines of bash. rbenv works well though (with one additional conf line), and chruby was working on support last time I checked.

RVM is pretty heavyweight. Why not something like chruby?

Re: Unix Tricks

#74

Earlier quoted context omitted.

The article doesn't say, so it's worth mentioning that you can type ctrl-R multiple times to search further back into command history.

I use C-r constantly. But sometimes I need to find a command, and then edit it before running it. What is the proper way to exit "search mode" and go into the normal "edit" mode?

C-e ?

Re: Unix Tricks

#75

Its implied on the list but not mentioned specifically. !! will be substituted with the last command you typed. So if your somebody like me who frequently types $ apt-get update Could not lock yada yada are you root? $ sudo apt-get update instead you can type $ apt-get update $ sudo !!

What I love about this is that if you up-arrow through your past commands, the "sudo !!" shows up as "sudo apt-get update"

Re: Unix Tricks

#76
post #75

Its implied on the list but not mentioned specifically. !! will be substituted with the last command you typed. So if your somebody like me who frequently types $ apt-get update Could not lock yada yada are you root? $ sudo apt-get update instead you can type $ apt-get update $ sudo !!

What I love about this is that if you up-arrow through your past commands, the "sudo !!" shows up as "sudo apt-get update"

Bash substitutions are done prior to execution so your history stays intact. Older open source projects are just amazing for how complete their feature set is.

Re: Unix Tricks

#77
Another one:

Use dcfldd instead of dd if you want to see how far your dd operation is progressing...

dcfldd if=[infile] of=[outfile] sizeprobe=if

So. Much. Better.

dcfldd also has many other useful options - read the man pages - and note that you'll have to install it from your linux distro's package repo beforehand.

Re: Unix Tricks

#78
post #29

man hier is pretty cool. It explains the root directory structure of the system.

definitely feel like this one was more widely known in the days of printed manuals.

Re: Unix Tricks

#79

Another one: Use dcfldd instead of dd if you want to see how far your dd operation is progressing... dcfldd if=[infile] of=[outfile] sizeprobe=if So. Much. Better. dcfldd also has many other useful options - read the man pages - and note that you'll have to install it from your linux distro's package repo beforehand.

You can also send SIGUSR1 to dd for progress info. From the manpage:

  Sending a USR1 signal to a running 'dd' process makes it print I/O statistics to standard error and then resume copying.

    $ dd if=/dev/zero of=/dev/null& pid=$!
    $ kill -USR1 $pid; sleep 1; kill $pid

    18335302+0 records in 18335302+0 records out 9387674624 bytes (9.4 GB) copied, 34.6279 seconds, 271 MB/s

Re: Unix Tricks

#80

You know what I hate? My history isn't aggregated in real time across all my Mac OS X terminal windows. You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly. Especially when I hit the up arrow to go back in my terminal history.

> Typing in long commands in the Mac OS X terminal and then them wrapping weirdly.

For all people who dont use Mac OS X:

This happens because your PS1 is wrongly set and bash cant calculate correctly the length left of your line. Try it out, by going back to default with no colors and crap and see how long it goes.

For mac os x users. The above wont help, dont even try it.

Post reply on HN