Go Back   The macosxhints Forums > OS X Help Requests > UNIX - Newcomers



Reply
 
Thread Tools Rating: Thread Rating: 60 votes, 4.98 average. Display Modes
Old 05-07-2002, 05:39 PM   #41
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
Red face add-alias v1.1

whoops. yeah, heh, it's a thing with the quotes. the ticks need to be backslash-escaped in the echo redirect. but vB needs to see two, dual, redundant, back-to-back backslashes to habla blah blah...

edit2: i should make this clearer. vBullitin, the system that runs this board, needs two backslashes together in the post editor to show one in the thread. hmm, not much clearer, but you'll either figure it out or you won't.
Code:
add-alias ()
{
   local name=$1 value="$2"
   echo alias $name=\\'$value\\' >> ~/.bash_aliases
   eval alias $name='$value'
   alias $name
}
edit: boy, that was a joyous editing session. i got some weird chars in my post and i think i ripped a hole in the fabric of space. hopefully, this will be complete.

Last edited by mervTormel; 05-07-2002 at 07:31 PM.
mervTormel is offline   Reply With Quote
Old 05-07-2002, 06:28 PM   #42
rusto
MVP
 
Join Date: Jan 2002
Location: Boston, MA
Posts: 1,489
Thanks, but dang those pesky escape characters!

One neat feature of your function is that you don't have to close the current terminal session to use the new aliases.
__________________
:: 3.4GHz Core i7 iMac 4GB RAM :: Black MacBook SR :: 10.7.2 :: iPhone 4 / iOS 5 ::
rusto is offline   Reply With Quote
Old 05-07-2002, 07:18 PM   #43
bluehz
MVP
 
Join Date: Jan 2002
Posts: 1,562
Thnx for the informative thread guys - I actually solved my prob via someone recommending this thread. On a related note - in my search for answer I ran across an interesting repository of user-submitted shell files. I posted this to the Hints page the other day - but it never made it in I guess.

http://www.dotfiles.com/

I would be a bit wary of simply grabbing other peoples stuff an instituting it - but it could be a great source to pick up tidbits from.
bluehz is offline   Reply With Quote
Old 05-07-2002, 07:44 PM   #44
Craig R. Arko
Site Admin
 
Join Date: Dec 2001
Location: Minneapolis, MN
Posts: 3,988
Thumbs up

Geez, I just wandered in here. Great work, folks. I am not worthy!

Is it possible to generate a summary of the findings to date? Maybe a book on the subject (I'm sure O'Reilly would be interested)?
Craig R. Arko is offline   Reply With Quote
Old 05-07-2002, 08:20 PM   #45
rusto
MVP
 
Join Date: Jan 2002
Location: Boston, MA
Posts: 1,489
One more thing, how do I get .bashrc to look to .bash_aliases? The function we have been fiddling with sets aliases fine for the current shell but no new ones.

btw, found your source for the function, merv, and there it looks like this:

Code:
# Function which adds an alias to the current shell and to
# the ~/.bash_aliases file.
addalias ()
{
   local name=$1 value="$2"
   echo alias $name=\\'$value\\' >> ~/.bash_aliases
   eval alias $name=\\'$value\\'
   alias $name
}
__________________
:: 3.4GHz Core i7 iMac 4GB RAM :: Black MacBook SR :: 10.7.2 :: iPhone 4 / iOS 5 ::
rusto is offline   Reply With Quote
Old 05-07-2002, 09:18 PM   #46
sao
Moderator
 
Join Date: Jan 2002
Location: Singapore
Posts: 4,237
Hi all,

Well, now that the old good thread came back to life, it's time to post an update on the subject.

So, for all the tcsh lovers out there...

Here is how my .cshrc file looks today :

Code:
source  /sw/bin/init.csh
date
set prompt="\! [%{\033[32m%}%n%{\033[0m%} @%{\033[36m%}%/%{\033[0m%}] : "
alias l         'ls -Ahl --color=always'
alias lh        'ls -Al --color=always'
alias ls        'ls -A --color=always'
alias m         'more'
alias top       'top -u -s 10'
set histfile = .history
set savehist = ( 250 merge )
set complete=enhance
alias lo        'logout'
alias fword    ' grep -i \!* /usr/share/dict/web2 '
xttitle pm@$cwd
alias cd       'chdir \!*;xttitle pm@$cwd'
alias pushd    'pushd \!*;xttitle pm@$cwd'
alias popd     'popd \!*;xttitle pm@$cwd'
alias back     'cd -'
alias h        'history'
alias psh      'pushd'
alias pop      'popd'
alias md       'mkdir'
alias krm      'rm -i'
alias r        'rehash'
alias cl       'cd \!* ; ls'
fortune
Probably the most interesting thing, besides a couple of new aliases, is that I manage to use xttitle (installed with fink) to display my location in the window title, and it works well with terminal.app, xterm, eterm, aterm, etc. thanks to a great tip from Enri Rothman's web site.

http://compsci.salve.edu/macosx.html

(a lot of good info on this site, and by the way, pmccann, another mathematician working hard on a mac, check it out).

From bash, I think you can change the xterm/aterm/Eterm/rxvt/ title like this:

echo -e "\e]2;This is the title\007"

and in the man console_codes you can see the other variants of window/icon title.

Truth is, I also installed bash and I'm learning the way, slowly. But not yet enough to start posting about it. Maybe next time.


Cheers...

Last edited by sao; 05-07-2002 at 10:56 PM.
sao is offline   Reply With Quote
Old 05-07-2002, 09:37 PM   #47
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
Quote:
Originally posted by rusto
One more thing, how do I get .bashrc to look to .bash_aliases? The function we have been fiddling with sets aliases fine for the current shell but no new ones...

put a call to ~/.bash_aliases in ~/.bashrc ?
Code:
if [ -e ~/.bash_aliases ]; then . ~/.bash_aliases; fi  # load .bash_aliases
mervTormel is offline   Reply With Quote
Old 05-08-2002, 12:03 AM   #48
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
okay, my previous reply was a little terse, so i'll flesh it out a little. this is bash specific in odor, but the fragrance applies to other shellage...

~/.bash_profile is automagically called on login by the bash executable, as per the man pages. this file performs the things you want to happen on the inital login session. one of those things is to load the ~./bashrc file.
Code:
# ~/.bash_profile

if [ -f ~/.bashrc ]; then . ~/.bashrc ; fi

date
who
biff y
echo "home size: `du -sh ~`"
fortune # -o
~/.bashrc is automagically called on a non-login shells (sub-shells) by the bash executable; this is the file to put things you want in every shell and sub-shell (aliases, functions, env variables). typically, this file won't have any commands that blab any output to stdout.

the file ~/.bash_aliases is not in the bash startup sequence. it's a user-invented file. therefore, it needs to be 'existed' and loaded.

the reason i broke out aliases to their own file was so i could define a reasonable, portable and mostly self-contained add_alias function and not worry about polluting the end of another file or of writing additional aliases beyond a premature exit or return.

since .bashrc is the meat of my shell brains, i have a 'return' at a logical place in my .bashrc and beyond that 'return' are notes and test code that i want to keep, so my .bashrc looks like:
Code:
production code
decision making code
calls to other files, like .bash_aliases

return

junk and embarrassing stuff
notes and epithets towards steve balmer
test code and stuff that can't pass for code
so, if i left aliases in .bashrc, they would be appended after junk, notes, and test code and never be executed because of the return command.

i realize this may be confusing; it's harder to explain than experience. a handy tip is to always have several shell windows open when you modify your startup scriptage so you can switch back to the un-tainted to fix things up. and test test test, lest you be unable to login to your shell to fix it.

feel free to ask questions and make suggestions (the non-lurid kind).
mervTormel is offline   Reply With Quote
Old 05-08-2002, 12:24 AM   #49
sao
Moderator
 
Join Date: Jan 2002
Location: Singapore
Posts: 4,237
MervTormel, rusto,

Sorry, just getting in the middle a little bit to finish my post from above.

Of course, if you want to display your location in the window title, without using xttitle, you can do the following:

create a file in your home directory named .settitle with:

Code:
alias settitle 'echo -n "^[]2;$cwd^G"'
settitle
alias cd 'cd \!*;settitle'
alias pushd 'pushd \!*;settitle'
alias popd 'popd \!*;settitle'
To type the ^[ characters into the file type ctrl-v followed by the ESC key.
The ^G character by pressing ctrl-v followed by ctrl-g.

After you created .settitle, add the following to your ~/.cshrc file:

source ~/.settitle

Now you should get your location in the window title.

Thank you, let's now continue with the bash education. (By the way MervTormel, what I wrote about bash title in my post above, does it make any sense?)


Cheers...

PS: Bluehz, for tidbits besides http://www.dotfiles.com you can also check http://www.shelldorado.com/shelltips/beginner.html

Last edited by sao; 05-08-2002 at 02:40 AM.
sao is offline   Reply With Quote
Old 05-08-2002, 09:28 AM   #50
bluehz
MVP
 
Join Date: Jan 2002
Posts: 1,562
Maybe I am missing someting here or its losing something in the text to HTML display translation. I tried the ctr-v followed by.... scenario and I get nothing - or I get the tcsh help facility. Why can I not just use the "^" provided on the keyboard?

Quote:
To type the ^[ characters into the file type ctrl-v followed by the ESC key.
The ^G character by pressing ctrl-v followed by ctrl-g.

Thx! Checkin it out right now...

Quote:
PS: Bluehz, for tidbits besides http://www.dotfiles.com you can also check [url]http://www.shelldorado.com/shelltips/beginner.html

ADD: shelldorado is great! Thanx for the turn-on. BYW - did you happen to visit the Tutorials page http://www.shelldorado.com/links/index.html#tutorials it is a HUGE page of links to UNIX related tutorials. Could take a while to digest all this!

Last edited by bluehz; 05-08-2002 at 09:46 AM.
bluehz is offline   Reply With Quote
Old 05-08-2002, 10:46 AM   #51
sao
Moderator
 
Join Date: Jan 2002
Location: Singapore
Posts: 4,237
bluehz,

Best, is to create the .settitle file with vim, I had trouble with pico to type the special characters. Don't miss any characters or it will not work.

Let me know.

Cheers...

PS: Wow, quite a few links to unix tutorials there.

Last edited by sao; 05-08-2002 at 10:50 AM.
sao is offline   Reply With Quote
Old 05-08-2002, 01:32 PM   #52
bluehz
MVP
 
Join Date: Jan 2002
Posts: 1,562
Yes - I think I figured that out - copy and paste doesn't work in pico. I don't get around very well in VIM, etc. Guess I'm gonna have to start learning....
bluehz is offline   Reply With Quote
Old 05-08-2002, 02:10 PM   #53
sao
Moderator
 
Join Date: Jan 2002
Location: Singapore
Posts: 4,237
bluehz,

Go for it. Learn a couple of commands in vim and you are done in five minutes. It's not so difficult, I promise. Or, if you still have XFree installed you can call gvim, the GUI version of vim, and there just type, save and quit.

Good luck.

Cheers...
sao is offline   Reply With Quote
Old 05-09-2002, 12:52 AM   #54
xchanyazy
All Star
 
Join Date: Jan 2002
Location: Dexter, MI, USA
Posts: 704
<flamebait>vim is the devil! Use Emacs!</flamebait>

Or xemacs, if you want a gui version.
__________________
- Greg

Happy user of OS X since the Public Beta.
Help Team Mac OS X cure cancer, Alzheimer's, ALS, Parkinson's, and more!
xchanyazy is offline   Reply With Quote
Old 05-09-2002, 01:47 AM   #55
sao
Moderator
 
Join Date: Jan 2002
Location: Singapore
Posts: 4,237
xchanyazy,

Yes, emacs, Xemacs are great. I suggested vim because I found is slighlty easier for a beginner)

By the way, in order to use all of them and not to be concerned about the devil, you need to be....
sao is offline   Reply With Quote
Old 05-09-2002, 07:09 PM   #56
stetner
MVP
 
Join Date: Jan 2002
Location: Brisbane, Australia
Posts: 1,108
The main reason I always use vi is because there are not many UNIX boxes that does not have it. At one time I tried using emacs, became quite comfortable with it, but then started cursing when I could not us it on certain machines (it is not installed by default on a lot of machines and has a huge footprint which precludes putting it on others). I then went back to good old vi which works the same every where and exists everywhere!

My opinion of course 8-)
__________________
Douglas G. Stetner
UNIX Live Free Or Die
stetner is offline   Reply With Quote
Old 05-09-2002, 09:19 PM   #57
bluehz
MVP
 
Join Date: Jan 2002
Posts: 1,562
I d/l, compiled and installed VIM today. Haven't had much chance to mess with it yet. VI just totally confuses me. Its not that I couldn't learn it in a few mins - its just I shouldn't have to spend an inordinate amount of time learning to use a simple text editor. I guess thats why so many people use tcsh - you can normally just poke and peck and get around. More than once I have gotten stuck in VI, can't go back, can't go forward - totally confounding. Obviously I don't know the secret code...ahahahaha....

Giving VIM a good try though....
bluehz is offline   Reply With Quote
Old 05-09-2002, 10:00 PM   #58
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
yeah, vi is a bit awkward at first. but stetner is correct. it's recommended to know, at least with a passing familiarity, because it is universally available on unix installs.

there's only a few notions and a handful of key sequences to know to be able to use vi at a minimal level. and get out of messes.

even tho the man pages has a fast start section that covers the minimum, it might be useful to start a vi thread somewhere.
mervTormel is offline   Reply With Quote
Old 05-09-2002, 10:28 PM   #59
stetner
MVP
 
Join Date: Jan 2002
Location: Brisbane, Australia
Posts: 1,108
Quote:
The only "intuitive" interface is the nipple. After that, it's all learned.

(Bruce Ediger, bediger@teal.csn.org, in comp.os.linux.misc, on X interfaces.)

That said, vi has two modes, insert and command mode. If you are not sure where you are, hit <ESC> and you are in command mode (two times if you happen to be in a 'raw keystroke entry mode IE have just hit ^V). Then just a ':q' to quit (or ':q!' to quit if the buffer has been changed, or ':wq' to write and quit).
If check out:www.google.com/search?hl=en&q=vi+cheat+sheet You will see there are a lot of cheat sheets to help you get started.

The two things I like best are key mapping and the search/replace. Key mapping lets you do something like (where ^V is control-V and ^[ is <ESC>:
Code:
:map g 0iStart of Line - ^V^[$aEnd of Line - ^V^[j
and change
Code:
aaa
bbb
ccc
ddd
   
To:

Start of Line - aaa - End of Line
Start of Line - bbb - End of Line
Start of Line - ccc - End of Line
Start of Line - ddd - End of Line
in 4 key strokes. Basically it maps the single stroke 'g' into the remaining stuff (IE 0 - go to begining of line i - insert 'Start....' the literal text until the <ESC>).

if you had:
Code:
Fish is good
Beef is good
Fish is good
Beef is good

A search/replace of:
:g/Fish/s/good/bad/

Turns it into:

Fish is bad 
Beef is good
Fish is bad 
Beef is good
(yeah, I know, fish is good for you! 8-)
Anyway, there are a million neat things you can do in vi (from the keyboard) that make it very good for hacking text.
__________________
Douglas G. Stetner
UNIX Live Free Or Die
stetner is offline   Reply With Quote
Old 05-10-2002, 12:31 AM   #60
sao
Moderator
 
Join Date: Jan 2002
Location: Singapore
Posts: 4,237
stetner,

Thanks for the input and the "nipple" memories.

Since Vim 6.1 became available through Fink, and I realized that I could launch gvim as long as I had X11 running, I never looked back.

Although it may look strange as vim has two modes, learning from scratch was fast and easy for me.


Cheers...

Last edited by sao; 05-10-2002 at 12:51 AM.
sao is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 10:35 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.