Extra Pepperoni

To content | To menu | To search

BBEdit

http://www.barebones.com/products/bbedit/

Entries feed - Comments feed

Wednesday, May 27 2009

BBEdit Multihost Multifile Comparison

Update 2009/07/02: Although I wrote this script specifically for comparing files, I have found that it also saves a lot of typing for editing individual remote files, cutting 14 characters of syntactic sugar down to 5: bbs<Tab> and a Space.


I often need to reconcile (partially or completely) one or more files on two or more machines. I often to use BBEdit's excellent "Find Differences" to do this, but loading the files into BBEdit can be awkward. I still hope someday Bare Bones will add support for remote files to their bbdiff command, but I'm not holding my breath. Today I whipped up a shell script to make it more convenient:

#!/bin/sh
# bsftp: Edit multiple files from multiple hosts.
# Usage: bsftp "host1 host2 host3" "/etc/passwd /etc/shadow /etc/group"

for file in $2
 do
  for host in $1
   do
    bbedit sftp://root@$host/$file
   done
 done

Monday, January 8 2007

Remote 'man' with BBEdit

I frequently need to read manual pages from Suns and Linux systems, but prefer to read in BBEdit. Today's trick facilitates this, by grabbing the manual page from a remote machine via ssh, unformatting it with col, and dumping it into a BBEdit window (which doesn't ask to be saved).

function manb () { ssh $1 man $2 | col -b | bbedit -t "$2@$1" --clean --view-top }

Usage is "manb host command", so "manb www up2date" opens a window titled "up2date@www" with www's up2date manual page.

Friday, December 29 2006

BBEdit and Subversion: the Fruit Roll-up Post

I use vi daily, but much prefer BBEdit. The way I integrate them has evolved over time (see previous posts here, Useful subversion shell aliases, and BBEdit Gems (which appears to be down right now). In particular, I no longer configure BBEdit directly in ~/.subversion/config.

The new improved integration uses BBEdit whenever it's available (I'm in front of the Mac), and falls back to the default (vi) when I'm connected via ssh.

First, I created ~/bin/edit.sh to hand off to BBEdit. I use edit.sh whenever BBEdit is appropriate:

#!/bin/sh
# Edit in BBEdit, for programs that don't support arguments in $EDITOR.
bbedit --wait --resume "$@"

Next, I configured my bash profile to prefer edit.sh when I'm not connected via ssh (which means when I am in front of the Mac or using ARD/VNC), as my EDITOR and PAGER. My profile doesn't automatically determine whether to use bbdiff for Subversion, because I sometimes find it necessary to use non-BBEdit diff for Subversion (there are cases where the svn-to-bbedit handoff doesn't work well, and I have ended up editing scratch files instead of the real files, for instance). Here's the snippet that does this, from my profile:

if [[ ! $SSH_TTY ]]
then
  if [ -x ~/bin/edit.sh ]
    then
      export EDITOR=~/bin/edit.sh
    else export EDITOR=vi
  fi
  if [ -x /usr/bin/bbedit ]
    then export PAGER="col -b | bbedit --clean --view-top"
  fi
else export EDITOR=vi
fi # [[ ! $SSH_TTY ]]

In addition, I set up aliases for reviewing output from the svn command, based on Bob's suggestions. I just copy and paste one or more lines from svn output to review changes in BBEdit:

alias  A='bbedit --wait'
alias AM='bbedit --wait'
alias  C='bbedit --wait'
alias  D='true'
alias  G='svn diff --diff-cmd bbdiff --extensions "--resume --wait"'
alias  I='true'
alias  M='svn diff --diff-cmd bbdiff --extensions "--resume --wait"'
alias  R='svn diff --diff-cmd bbdiff --extensions "--resume --wait"'
alias  U='bbedit --wait'

I update and then review status so often that I built my own TLA:

alias sus='svn update

Monday, May 22 2006

BBEdit and Subversion

BBEdit and Subversion now play well together (actually it's since BBEdit 8.1, but I hadn't noticed at the time). I added a few lines to ~/.subversion/config:

[helpers]
diff-cmd = bbdiff
extensions = --wait --resume

Now "svn diff" (with or without arguments) does the right thing.

Update: svn honors $EDITOR.

Wednesday, May 3 2006

Using bbedit as My EDITOR and PAGER

When I'm in front of the Mac, I want to use use BBEdit as my EDITOR and PAGER. When I'm connected via ssh from another computer, I need to fall back to vi and less. The following snippets handle this for me. The first one goes in a shell initialization file such as .profile or .bashrc, and the second one is a separate shell script.

if [[ ! $SSH_TTY ]]
 then
  if [ -x ~/bin/edit.sh ]
   then export EDITOR=~/bin/edit.sh
  fi
  if [ -x /usr/bin/bbedit ]
   then export PAGER="col -b | bbedit --clean --view-top"
  fi
fi # [[ ! $SSH_TTY ]]
pepper@pepperbook:~$ cat bin/edit.sh 
#!/bin/sh
# Edit in BBEdit, for programs that don't support arguments in $EDITOR.
bbedit --wait --resume "$@"

BBEdit's command-line helper (bbedit), can invoke BBEdit, but normally returns immediately after passing along the specified file(s) -- it doesn't wait for the user to finish editing the file, as a standard UNIX editor would, so Bare Bones provides the -w option to make bbedit wait to return. Unfortunately, some programs won't run a program with arguments as EDITOR, so it has to be embedded into a shell-script that adds --wait --resume internally.

The PAGER bit is similar, and inspired by a TidBITS-Talk thread.