Edit directory in BBedit

localhost% bbedit directoryName

causes BBedit to open a file browser window on that directory…yeah, I like that.

For the indexor: How do I do the equivalent of an emacs “dired” on a Mac OS X folder if I am using BBedit as my primary editor

For the compatability folks: emacs dirname

fsck on reboot

Using Disk Utility from the startup cd, or booting to single-user mode (hold down command-s just after chime) and at the “#” prompt type “fsck -y” repeat that command until no errors are reported, then type “exit” your mac will continue to boot.

Short-circuit shell commands

mac 131 work % [[ "a" > "A" ]] && echo fred
fred
mac 132 work % [[ "a" > "A" ]] || echo fred
mac 133 work % [[ "a" > "A" ]] && [[ "a" < "n" ]] && echo fred
fred
mac 138 work % foo="9"
mac 139 work % [[ "$foo" < "A" ]] && foo="defaultString"
mac 140 work % echo $foo
defaultString
mac 141 work % foo=" Some String"
mac 142 work % [[ "$foo" < "A" ]] && foo="defaultString"
mac 143 work %
mac 143 work % echo $foo
defaultString
mac 144 work % foo="Some String"
mac 145 work % [[ "$foo" < "A" ]] && foo="defaultString"
mac 146 work % echo $foo
Some String
mac 147 work % foo=""
mac 148 work % [[ "$foo" < "A" ]] && foo="defaultString"
mac 149 work % echo $foo
defaultString
mac 150 work %

basename and dirname

basename and dirname are programs – read process creation. Shell substitution can be much quicker and far more obscure.

basename is ${ARG##*/}

dollar-leftcurlybrace-A-R-G-sharp-sharp-asterisk-slash-rightcurlybrace

dirname is ${ARG%/*}

dollar-leftcurlybrace-A-R-G-percent-slash-asterisk-rightcurlybrace

Change the prompt in "sh"

I set my prompt in .profile to

PS1="%m %! %c %# "; export PS1

which gives me host – command number – last part of path – # or % depending on root or not…

Reduce Disk Consumption

Get rid of all non-english files in application bundles

find / ! -name "English.lproj" -name "*.lproj" -type d -exec rm -r -- true ;

System Speedups

These things are all one-liners – watch out for the wrap in your browser.

to make window resizing and application load time faster :

sudo renice -20 -p `ps -ax | grep WindowServer | cut -c1-5 | sort | head -1`
pre-bind files in os x (optimize/defragment) :

sudo update_prebinding -root / 

Selective IMPORT from RBR file

From Ian Smith of Oracle:

If you go the EXPORT and IMPORT route then may I recommend the following:

rmu/extract/item=import

It already generates an IMPORT script.

Modify the IMPORT command to redefine any indices you want to change. IMPORT will replace the definitions in the RBR file with those on the command line. BUT make sure they are defined inside the IMPORT command (i.e. Only one semicolon)

In V7.1 you can RMU/LOAD from the RBR file (V7.1.0.2 and later documented next release 🙂

RMU/LOAD/MATCH_NAME personnel employees pers.rbr

You can then submit batch jobs to load from the RBR after creating the database using IMPORT … NO DATA.

Rdb Datatypes Decoded

-- Copyright 2002 - Oracle Corporation
-- Example CASE expression to translate Rdb system table
-- type information to SQL text
--

select
  RDB$FIELD_NAME as Column_Name,    !as "Column Name"
  case RDB$FIELD_TYPE
    when 6  then          -- Byte Integer
      'TINYINT' ||
      case RDB$FIELD_SCALE
        when 0 then ''
        else
          ' (' || CAST(-RDB$FIELD_SCALE AS VARCHAR(3)) || ')'
      end
    when 7  then          -- Word Integer
      'SMALLINT' ||
      case RDB$FIELD_SCALE
        when 0 then ''
        else
          ' (' || CAST(-RDB$FIELD_SCALE AS VARCHAR(3)) || ')'
      end
    when 8  then          -- Longword Integer
      'INTEGER' ||
      case RDB$FIELD_SCALE
        when 0 then ''
        else
          ' (' || CAST(-RDB$FIELD_SCALE AS VARCHAR(3)) || ')'
      end
    when 9  then          -- Quadword Integer
      'BIGINT' ||
      case RDB$FIELD_SCALE
        when 0 then ''
        else
          ' (' || CAST(-RDB$FIELD_SCALE AS VARCHAR(3)) || ')'
      end
    when 10 then 'REAL'       -- F_floating
    when 27 then 'DOUBLE PRECISION' -- G_floating
    when 14 then          -- Character-coded text
      'CHAR (' ||
      CAST(RDB$FIELD_LENGTH AS VARCHAR(5)) || ')'
    when 37 then          -- Varying Character-coded Text
      'VARCHAR (' ||
      CAST(RDB$FIELD_LENGTH AS VARCHAR(5)) || ')'
    when 21 then 'DECIMAL'      -- Packed decimal string
    when 261 then
      'LIST OF BYTE VARYING (' ||
      CAST(RDB$SEGMENT_LENGTH AS VARCHAR(5)) || ')'
    when 35 then
      -- Absolute Date and Time
      case RDB$FIELD_SUB_TYPE
        when 0  then
          'DATE VMS'
        when 56 then
          'TIME (' ||
          CAST(-RDB$FIELD_SCALE AS VARCHAR(3)) || ')'
        when 7  then
          'DATE ANSI'
        when 63 then
          'TIMESTAMP (' ||
          CAST(-RDB$FIELD_SCALE AS VARCHAR(3)) || ')'
        else 'INTERVAL ' ||
          case RDB$FIELD_SUB_TYPE
            when 513 then
              'YEAR(' ||
              CAST(RDB$SEGMENT_LENGTH AS VARCHAR(9)) || ')'
            when 515 then
              'YEAR(' ||
              CAST(RDB$SEGMENT_LENGTH AS VARCHAR(9)) ||
              ') TO MONTH'
            when 514 then
              'MONTH(' ||
              CAST(RDB$SEGMENT_LENGTH AS VARCHAR(9)) || ')'
            when 516 then
              'DAY(' ||
              CAST(RDB$SEGMENT_LENGTH AS VARCHAR(9)) || ')'
            when 524 then
              'DAY(' ||
              CAST(RDB$SEGMENT_LENGTH AS VARCHAR(9)) ||
              ') TO HOUR'
            when 540 then
              'DAY(' ||
              CAST(RDB$SEGMENT_LENGTH AS VARCHAR(9)) ||
              ') TO MINUTE'
            when 572 then
              'DAY(' ||
              CAST(RDB$SEGMENT_LENGTH AS VARCHAR(9)) ||
              ') TO SECOND(' ||
              CAST(-RDB$FIELD_SCALE AS VARCHAR(3)) || ')'
            when 520 then
              'HOUR(' ||
              CAST(RDB$SEGMENT_LENGTH AS VARCHAR(9)) || ')'
            when 536 then
              'HOUR(' ||
              CAST(RDB$SEGMENT_LENGTH AS VARCHAR(9)) ||
              ') TO MINUTE'
            when 568 then
              'HOUR(' ||
              CAST(RDB$SEGMENT_LENGTH AS VARCHAR(9)) ||
              ') TO SECOND(' ||
              CAST(-RDB$FIELD_SCALE AS VARCHAR(3)) || ')'
            when 528 then
              'MINUTE(' ||
              CAST(RDB$SEGMENT_LENGTH AS VARCHAR(9)) || ')'
            when 560 then
              'MINUTE(' ||
              CAST(RDB$SEGMENT_LENGTH AS VARCHAR(9)) ||
              ') TO SECOND(' ||
              CAST(-RDB$FIELD_SCALE AS VARCHAR(3)) || ')'
            when 544 then
              'SECOND(' ||
              CAST(RDB$SEGMENT_LENGTH AS VARCHAR(9)) ||
              ',' ||
              CAST(-RDB$FIELD_SCALE AS VARCHAR(3)) || ')'
            else
              '(unknown interval)'
          end
      end
    else
      '(unknown data type)'
  end as Data_Type          ! as "Data Type"
from RDB$FIELDS
where RDB$FIELD_NAME not starting with 'RDB';

RMU/Repair – Caveat Emptor

Don’t EVER type a control-Y at an “RMU/REPAIR/ABM dbname” command where you have forgotten the /AREA qualifier.

Bad things happen to the RDB$SYSTEM area.

Hopefully completing a full RMU/REPAIR/ABM command will fix the damage.