sublime.plugin.zsh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # Sublime Text Aliases
  2. () {
  3. if [[ "$OSTYPE" == linux* ]]; then
  4. local _sublime_linux_paths
  5. _sublime_linux_paths=(
  6. "$HOME/bin/sublime_text"
  7. "/opt/sublime_text/sublime_text"
  8. "/opt/sublime_text_3/sublime_text"
  9. "/usr/bin/sublime_text"
  10. "/usr/local/bin/sublime_text"
  11. "/usr/bin/subl"
  12. "/opt/sublime_text_3/sublime_text"
  13. "/usr/bin/subl3"
  14. )
  15. for _sublime_path in $_sublime_linux_paths; do
  16. if [[ -a $_sublime_path ]]; then
  17. st_run() { $_sublime_path $@ >/dev/null 2>&1 &| }
  18. st_run_sudo() {sudo $_sublime_path $@ >/dev/null 2>&1}
  19. alias sst=st_run_sudo
  20. alias st=st_run
  21. break
  22. fi
  23. done
  24. elif [[ "$OSTYPE" = darwin* ]]; then
  25. local _sublime_darwin_paths
  26. _sublime_darwin_paths=(
  27. "/usr/local/bin/subl"
  28. "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
  29. "/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
  30. "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl"
  31. "$HOME/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
  32. "$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
  33. "$HOME/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl"
  34. )
  35. for _sublime_path in $_sublime_darwin_paths; do
  36. if [[ -a $_sublime_path ]]; then
  37. subl () { "$_sublime_path" $* }
  38. alias st=subl
  39. break
  40. fi
  41. done
  42. elif [[ "$OSTYPE" = 'cygwin' ]]; then
  43. local sublime_cygwin_paths
  44. sublime_cygwin_paths=(
  45. "$(cygpath $ProgramW6432/Sublime\ Text\ 2)/sublime_text.exe"
  46. "$(cygpath $ProgramW6432/Sublime\ Text\ 3)/sublime_text.exe"
  47. )
  48. for _sublime_path in $_sublime_cygwin_paths; do
  49. if [[ -a $_sublime_path ]]; then
  50. subl () { "$_sublime_path" $* }
  51. alias st=subl
  52. break
  53. fi
  54. done
  55. fi
  56. }
  57. alias stt='st .'
  58. find_project()
  59. {
  60. local PROJECT_ROOT="${PWD}"
  61. local FINAL_DEST="."
  62. while [[ $PROJECT_ROOT != "/" && ! -d "$PROJECT_ROOT/.git" ]]; do
  63. PROJECT_ROOT=$(dirname $PROJECT_ROOT)
  64. done
  65. if [[ $PROJECT_ROOT != "/" ]]; then
  66. local PROJECT_NAME="${PROJECT_ROOT##*/}"
  67. local SUBL_DIR=$PROJECT_ROOT
  68. while [[ $SUBL_DIR != "/" && ! -f "$SUBL_DIR/$PROJECT_NAME.sublime-project" ]]; do
  69. SUBL_DIR=$(dirname $SUBL_DIR)
  70. done
  71. if [[ $SUBL_DIR != "/" ]]; then
  72. FINAL_DEST="$SUBL_DIR/$PROJECT_NAME.sublime-project"
  73. else
  74. FINAL_DEST=$PROJECT_ROOT
  75. fi
  76. fi
  77. st $FINAL_DEST
  78. }
  79. function create_project() {
  80. local _target=$1
  81. if [[ "${_target}" == "" ]]; then
  82. _target=$(pwd);
  83. elif [[ ! -d ${_target} ]]; then
  84. echo "${_target} is not a valid directory"
  85. return 1
  86. fi
  87. local _sublime_project_file=$_target/$(basename $_target).sublime-project
  88. if [[ ! -f $_sublime_project_file ]]; then
  89. touch $_sublime_project_file
  90. echo -e "{" >> $_sublime_project_file
  91. echo -e "\t\"folders\":" >> $_sublime_project_file
  92. echo -e "\t\t[{" >> $_sublime_project_file
  93. echo -e "\t\t\t\"path\": \".\"," >> $_sublime_project_file
  94. echo -e "\t\t\t\"file_exclude_patterns\": []" >> $_sublime_project_file
  95. echo -e "\t\t}]" >> $_sublime_project_file
  96. echo -e "}" >> $_sublime_project_file
  97. echo -e "New Sublime Text project created:\n\t${_sublime_project_file}"
  98. fi
  99. }
  100. alias stp=find_project
  101. alias stn=create_project