sublime.plugin.zsh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. if [[ $('uname') == 'Linux' ]]; then
  2. local _sublime_linux_paths > /dev/null 2>&1
  3. _sublime_linux_paths=(
  4. "$HOME/bin/sublime_text"
  5. "/opt/sublime_text/sublime_text"
  6. "/opt/sublime_text_3/sublime_text"
  7. "/usr/bin/sublime_text"
  8. "/usr/local/bin/sublime_text"
  9. "/usr/bin/subl"
  10. "/opt/sublime_text_3/sublime_text"
  11. "/usr/bin/subl3"
  12. )
  13. for _sublime_path in $_sublime_linux_paths; do
  14. if [[ -a $_sublime_path ]]; then
  15. st_run() { $_sublime_path $@ >/dev/null 2>&1 &| }
  16. st_run_sudo() {sudo $_sublime_path $@ >/dev/null 2>&1}
  17. alias sst=st_run_sudo
  18. alias st=st_run
  19. break
  20. fi
  21. done
  22. elif [[ "$OSTYPE" = darwin* ]]; then
  23. local _sublime_darwin_paths > /dev/null 2>&1
  24. _sublime_darwin_paths=(
  25. "/usr/local/bin/subl"
  26. "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
  27. "/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
  28. "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl"
  29. "$HOME/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
  30. "$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
  31. "$HOME/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl"
  32. )
  33. for _sublime_path in $_sublime_darwin_paths; do
  34. if [[ -a $_sublime_path ]]; then
  35. subl () { "$_sublime_path" $* }
  36. alias st=subl
  37. break
  38. fi
  39. done
  40. elif [[ "$OSTYPE" = 'cygwin' ]]; then
  41. local _sublime_cygwin_paths > /dev/null 2>&1
  42. _sublime_cygwin_paths=(
  43. "$(cygpath $ProgramW6432/Sublime\ Text\ 2)/sublime_text.exe"
  44. "$(cygpath $ProgramW6432/Sublime\ Text\ 3)/sublime_text.exe"
  45. )
  46. for _sublime_path in $_sublime_cygwin_paths; do
  47. if [[ -a $_sublime_path ]]; then
  48. subl () { "$_sublime_path" $* }
  49. alias st=subl
  50. break
  51. fi
  52. done
  53. fi
  54. alias stt='st .'
  55. find_project()
  56. {
  57. local PROJECT_ROOT="${PWD}"
  58. local FINAL_DEST="."
  59. while [[ $PROJECT_ROOT != "/" && ! -d "$PROJECT_ROOT/.git" ]]; do
  60. PROJECT_ROOT=$(dirname $PROJECT_ROOT)
  61. done
  62. if [[ $PROJECT_ROOT != "/" ]]; then
  63. local PROJECT_NAME="${PROJECT_ROOT##*/}"
  64. local SUBL_DIR=$PROJECT_ROOT
  65. while [[ $SUBL_DIR != "/" && ! -f "$SUBL_DIR/$PROJECT_NAME.sublime-project" ]]; do
  66. SUBL_DIR=$(dirname $SUBL_DIR)
  67. done
  68. if [[ $SUBL_DIR != "/" ]]; then
  69. FINAL_DEST="$SUBL_DIR/$PROJECT_NAME.sublime-project"
  70. else
  71. FINAL_DEST=$PROJECT_ROOT
  72. fi
  73. fi
  74. st $FINAL_DEST
  75. }
  76. alias stp=find_project