Tugger the SLUGger!SLUG Mailing List Archives

[SLUG] Re: useful bash tricks thread



On Feb 6, 9:06 pm, Tony Sceats <t...@xxxxxxxxxxx> wrote:
> It's been a while since there's been a thread like this, so I thought it
> would be fun :)
>
> so, have you got any?
>
> I've got 2 to share today:
>
> alt >and then
> alt <
>

woo, that's kinda interesting.
It seems to pick the last "word" for each entry in the command-line
history?

Definitely second ctrl-r; I can't imagine a world without it.. Well i
can, I used to work with an older unix guy who used some older version
of bourne or c-shell and used !<pattern> (something like that) to run
previous commands.  No, never again.  Mind you, I set my shell to use
vi mode (set -o vi) which I think would freak out a lot of people.


I often have several files of related commands that I "source" into my
current shell.
This isn't a trick, more a set of conventions which I've found useful
to help keep me on top of things.
eg

  % . some_file.sh

This file would have the following format:

  h() {
    less <<-EOF
    VAR1: $VAR1
    VAR2: $VAR2
    ...

    func1 - do X
    func2 - do Y
EOF
  }

  VAR1=some_val1
  VAR2=some_val2
  ...

  func1() {
    ...
  }
  func2() {
    ...
  }

Then you can simply do:
  % func1 ...
to run your routine.
  % h
will list the commands and their descriptions assuming you've
documented them.
There are number of plain words you can use for your function names:
go,show,build,change,list,check,log,update,start,stop etc

You might do this to parcel up a bunch of related commands for some
area or thing.  For instance, managing a database.  'go' might take
you to conf directory or put you into the database shell etc etc  It's
also a good place to stash notes if you're learning something or
documenting it - either as comments or in the h() or simply in the
functions themselves. Listing things like relevant locations and
filenames as shell VARS is good documentation too.

My other even more OT tip: if you use the commandline a lot and you
haven't tried "screen", try it and become the super nerd you were
always meant to be.

--
Daniel Bush