149 days ago · Tech · hide · Fediverse post

I nearly always open Sublime Text from the command line using subl and have specific requirements for when it should open a new window or re-use one. If I'm opening a directory, then I would like it to re-use the same window if I have previously opened that directory. However if I open a random file, I never want that file in the last directory window as it's unrelated. To do this I wrote a simple bash function: # subl: wrapper that opens files in a new window, and reuses the window # for directories subl() { local args=() opts=() for a in "$@"; do if [[ "$a" == -* ]]; then opts+=("$a") else args+=("$a") fi done # No path argument means the current directory [[ ${#args[@]} -eq 0 ]] && args=(.) if [[ ${#args[@]} -eq 1 && -d "${args[0]}" ]]; then # Single directory: open in same window command subl "${opts[@]}" "${args[0]}" else # File(s): so open in a new window command subl -n "${opts[@]}" "${args[@]}" fi } Firstly we determine which parameters on the command line are arguments and…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town