- Installation
sudo port install bash
- Add it to your shells: add installed bash to
/etc/shells
sudo vim /etc/shells
| # Jump back | |
| cd - | |
| # add sudo to last command | |
| sudo !! | |
| # replace a word in last command | |
| ^cmd1^cmd2 | |
| # Remove surplus carriage returns in windows text files |
| # Quickly count, -f disable sorting, adding . and .. | |
| ls -f directory | wc -l | |
| # Quickly remove files | |
| rsync -a --delete empty_directory/ directory/ | |
| find directory -delete | |
| # Quickly copy files | |
| rsync -a source/ target/ | |
| # Copy list of files |
| tr -d '\015\032' < windows_file > unix_file |
| files=(/my/dir/*) | |
| printf "%s\n" "${files[RANDOM % ${#files[@]}]}" |
| tell application "Messages" | |
| set theBuddy to buddy "someone@some.domain" of service "Jabber" | |
| send "Hi" to theBuddy | |
| end tell |
| ActionScript: source.actionscript.2 | |
| AppleScript: source.applescript | |
| ASP: source.asp | |
| Batch FIle: source.dosbatch | |
| C#: source.cs | |
| C++: source.c++ | |
| Clojure: source.clojure | |
| CoffeeScript: source.coffee | |
| CSS: source.css | |
| D: source.d |
| # change directory and sync Finder window | |
| sd () { | |
| # change terminal directory | |
| cd "$@" || return | |
| # sync Finder window or open new one if not exists | |
| osascript -e "tell application \"Finder\" | |
| if front Finder window exists then | |
| set target of front Finder window to (""\"$PWD\""" as POSIX file) | |
| else | |
| open (""\"$PWD\""" as POSIX file) |
| # Use tar to direct output to standard output "-" and use gzip to compress | |
| tar -cf - <source_file> | gzip -1 > <destination_file> | |
| # Same effect, be sure to put <destination_file> directly behind -f option | |
| tar -czf <destination_file> <source_file> | |
| # Untar | |
| tar -xzf <tar_file> |
| function [combination] = batchCombine(funhandle, indir, varargin) | |
| %BATCHCOMBINE Process multiple files and combine the results into a cell array | |
| % BATCHCOMBINE(FUNC, INDIR) processes every file or directory in | |
| % INDIR using processing funtion FUNC. | |
| % | |
| % FUNC is a function handle that takes source filename as input variables. | |
| % For example, if FUNC = @foo, then BATCHCOMBINE calls foo(infile) to | |
| % every infile in INDIR. | |
| % | |
| % BATCHCOMBINE(..., 'para1', value1, 'para2', value2, ...) takes extra |