michaelfox + bash   147

bobthecow's gist: 700545 — Gist
ls_dead_branches.sh

#!/bin/bash

cd "./$(git rev-parse --show-cdup)"

for branch in $(git branch | tr -d " |*" | grep -v "(develop|production)"); do
[[ -z $(git diff develop...$branch) ]] && echo $branch
done
bash  shell  git  branch 
october 2011 by michaelfox
Snipt - binaryghost - Transcode with Alfred w/Progress in bar | Share and store code or command snippets.
#!/bin/bash
#transcode.sh
#By Don Southard aka @binaryghost
#
#[UPDATE 6/01/2011 08:01:15PM]
#Idea for Alfred progress bar by Andreas Heiberg
#Code by Don Southard
bash  shell  cli  handbrake  script  encode  convert 
september 2011 by michaelfox
UTI Property List Helper
### Description

In Mac OS X 10.3, Apple introduced a new scheme for identifying data types called [Uniform Type Identifiers][1].

One requirement that Mac OS X puts on any application that wants to use these identifiers is that it declare them in its Info.plist—not just in [CFBundleDocumentTypes][2] and [NSServices][3], but also in [UTImportedTypeDeclarations][4] and [UTExpertedTypeDeclarations][5]. Otherwise, Mac OS X 10.4 and later will ignore your application's uses of those UTIs elsewhere in your Info.plist.

This creates a lot of work for you, especially when importing a type declaration. Exporting a new declaration is easy, because it's your type: you can make up whatever you want. But to import a declaration, you must gather information about it and construct the dictionary yourself. This gets tedious, especially for some types (such as image types) that you may import in one application after another.

UTI Property List Helper is an application to solve this problem for you.

![The UTI Property List Helper window contains a table view, wherein you enter the UTIs, and two text views: one showing the CFBundleDocumentTypes array, and the other showing the UTImportedTypeDeclarations array.][6]


Simply add types to the list in the upper half of the window, and UTI Property List Helper will automatically update the two arrays in the lower half. When you're done, either select and copy each array's XML text into your Info.plist, or save it to a file.

### Mercurial repository

If you want to contribute bug-fixes or enhancements to UTIPropertyListHelper, the easiest way to do that is to clone [the Mercurial repository for UTIPropertyListHelper][7]. To do this, type this command into a terminal:

hg clone http://boredzo.org/uti-plist-helper/hg UTI-Plist-Helper

I provide UTIPlistHelper—the application, and its source code—under a three-clause BSD license. For more information, see the file named LICENSE.txt that comes with it.

[1]: http://developer.apple.com/documentation/Carbon/Conceptual/understanding_utis/
[2]: http://developer.apple.com/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/PListKeys.html#//apple_ref/doc/uid/20001431-101685
[3]: http://developer.apple.com/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/PListKeys.html#//apple_ref/doc/uid/20001431-107265
[4]: http://developer.apple.com/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/PListKeys.html#//apple_ref/doc/uid/20001431-114192
[5]: http://developer.apple.com/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/PListKeys.html#//apple_ref/doc/uid/20001431-SW7
[6]: http://boredzo.org/UTI_Plist_Helper.png
[7]: http://boredzo.org/hg
shell  scripting  bash  uti  plist  tools  osx  xml  mac 
september 2011 by michaelfox
Use the Bash trap Statement to Clean Up Temporary Files | Linux Journal
The trap statement in bash causes your script to execute one or more commands when a signal is received. One of the useful things you can use this for is to clean up temporary files when your script exits.

To execute code when your script receives a signal, use the following syntax:

trap arg sigspec...
The "arg" is the command to execute. If the command contains spaces, quote it. You can include multiple commands by separating them with semicolons. For more complex things, put your exit code in a function and just invoke the function. The "sigspec" list is a list of signals to trap and then execute "arg" (if/when they occur). For example, to remove a file on EXIT, do the following:

trap "rm -f afile" EXIT
Note that EXIT is not a real signal (do kill -l to see all signals); it is synthesized by bash.

Be careful using wildcards in "arg", because if they are unquoted or quoted with double quotes, they get expanded when the trap statement is encountered and not when "arg" is executed. For example, if you have a file named "abc.tmp" and the following trap statement is executed:

trap "rm -f *.tmp" EXIT
the command that gets executed when the script exits is "rm -f abc.tmp" and not "rm -f *.tmp". To avoid this problem, use single quotes.

If you create temporary files at various places in your code and you don't use a naming convention that would allow you to use a wild card in your trap statement and you don't want to worry about changing your trap statement as your code evolves, you could write something like this to allow you to add new trap commands that get executed on exit:

#!/bin/bash

declare -a on_exit_items

function on_exit()
{
for i in "${on_exit_items[@]}"
do
echo "on_exit: $i"
eval $i
done
}

function add_on_exit()
{
local n=${#on_exit_items[*]}
on_exit_items[$n]="$*"
if [[ $n -eq 0 ]]; then
echo "Setting trap"
trap on_exit EXIT
fi
}

touch $$-1.tmp
add_on_exit rm -f $$-1.tmp

touch $$-2.tmp
add_on_exit rm -f $$-2.tmp

ls -la
Here the function add_on_exit() adds commands to an array, and the on_exit() function loops through the commands in the array and executes them on exit. The on_exit function gets set as the trap command the first time add_on_exit is called.
bash  shell  scripting  trap 
april 2011 by michaelfox
« earlier      

related tags

aliases  ansi  antipatterns  apache  api  app  apple  applescript  automation  backup  bash  benchmarking  bestpractices  bittorrent  blog  boilerplate  books  branch  browser  c  character  cheatsheet  cli  cocoa  code  collection  color  colors  colorscheme  command  commandline  commands  compress  config  console  context  convert  converter  core  coredata  cron  css  curl  customization  desktop  development  dialog  docs  dotfiles  download  ebooks  encode  environment  error  escape  etc  find  firefox  forum  framework  free  geeklet  geektool  generator  gist  git  github  github-repo  grep  growl  gui  guide  guidelines  guides  hack  hacks  handbrake  history  howto  http  inputrc  inspiration  inspiration:dotfiles  interactive  ios  iphone  irc  iterm  java  javascript  keyboard  keychain  library  line  linux  list  ls  mac  mail  man  manuals  math  media  menu  minify  mysql  nerdtool  node  node.module  nodejs  notification  notifications  objective-c  oop  options  osx  passwords  pastie  pastie-325104  patterns  pentadactyl  php  phpsh  plist  plugins  preview  productivity  profile  programming  prompt  prompts  proxy  push  python  readline  reference  regiestry  remote  replace  repository  resources  rest  rsync  ruby  script  scripting  scripts  security  sed  server  settings  setup  sftp  shell  shopt  shortcut  snippets  social  software  sql  sqlite  ssh  style  svn  symbol  sysadmin  tabcompletion  tail  template  terminal  textexpander  textmate  theme  tips  todo  tools  top  transmission  trap  tutorial  twitter  ubuntu  unicode  unix  update  uti  ux  video  videolan  vim  vimeo  vlc  webdev  website  wiki  windows  wordpress  xml  xterm  youtube  zsh   

Copy this bookmark:



description:


tags: