Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

bash, AWK, sips. A couple of bash commands I use daily:

cdf - change directory to the folder open in (Mac) Finder

  cdf () {
    currFolderPath=$( /usr/bin/osascript <<EOT
      tell application "Finder"
        try
          set currFolder to (folder of the front window as alias)
        on error
          set currFolder to (path to desktop folder as alias)
        end try
        POSIX path of currFolder
      end tell
    EOT )
    echo "cd to \"$currFolderPath\""
    cd "$currFolderPath"
  }

  #dlm - "dlm filename" downloads filename.mp4 from URL in clipboard until its finished, resuming if interrupted
  fname=$(pbpaste)
  echo "Download $fname as $1.mp4 : "
  until curl -C - -kLo $1.mp4 "$fname"
  do
    sleep 5
  done


I don't use finder that much. My workflow usually involves finding stuff in the terminal and then using `open .` to open it in finder if needed.

But that snipped was neet! So I'm adding it to my dotfiles.


Where do you put this bash script?


~/.bash_profile is the macOS equivalent of a .bashrc

It's also possible that the author is source-ing it (spelled that way intentionally :\) ) from another file in their .bash_profile

Note also that the author of the comment above was fast and loose with their description of dlm, and if you copypaste it as-written, it'll bomb. (Perhaps obvious, but you did ask where to put it!)


Ah thank u, yes, sorry. I have dlm saved as a shell script file. I didn't paste here the first-line bash shebang, which would have made that clearer.

Maybe I use most:

  alias ..='cd ../'
Then ".." moves up to the parent directory.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: