mkautostart 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/sh
  2. # revision 2
  3. # 01micko 131202
  4. # the design is so it can be called from a pinstall.sh, or even
  5. # 3builddistro in woof and it can also run interactively so that
  6. # users can roll their own easily.
  7. ver=0.1
  8. # target and temporary writing place
  9. TARGET=$XDG_CONFIG_HOME/autostart
  10. TMP=/tmp/${RANDOM}
  11. err()
  12. {
  13. echo "error in name"
  14. exit 1
  15. }
  16. desktop_func()
  17. {
  18. # sanity check - first char must be alpha
  19. echo ${thename::1} | grep -q [a-zA-Z] || err
  20. # build the file
  21. echo -e \
  22. "[Desktop Entry]\nEncoding=UTF-8\nType=Application\nNoDisplay=true" > $TMP
  23. echo "Name=${thename}" >> $TMP
  24. echo -n "Exec=${thename}" >> $TMP
  25. [ "$option" ] && echo -n " "$option"" >> $TMP
  26. echo "" >> $TMP # carriage return
  27. }
  28. usage_func()
  29. {
  30. echo -e "${0##*/}-${ver} - creates simple desktop files for autostart.\n"
  31. echo -e "\t${0##*/} [executable_name] [-option(s)] :\n\t\t- automatically \
  32. creates \n\t\t\"[executable_name].desktop\" in \$XDG_CONFIG_HOME/autostart/ \
  33. \n\t\twith optional arguments, useful if called from a script. \
  34. \n\t\tSpecial characters (\",*,\,$) need to be escaped."
  35. echo -e "\t${0##*/} :\n\t\t- runs this script interactiveley in virtual terminal."
  36. exit 0
  37. }
  38. interactive()
  39. {
  40. # loop to get sane input
  41. echo "Type the name of executable that you want to autostart, NO SPACES"
  42. while [ 1 ];do
  43. read thename
  44. case $thename in
  45. "")echo "try again" && continue ;;
  46. *)echo "$thename" | grep -q " " && continue || break;;
  47. esac
  48. done
  49. echo
  50. echo -e "Now, optionally, you can pass paramaters to the executable. \
  51. \nIf you don't know, leave this field blank. \
  52. \nEXAMPLE: \
  53. \nIn the case of retrovol you would probably want to pass the \"-hide\" \
  54. option. \
  55. \nType it without quotes and press ENTER, or ENTER only for no options."
  56. read option
  57. desktop_func
  58. echo -e "\nBelow is the entry to be written to ${thename}.desktop. \
  59. \nDoes this look OK?\n"
  60. echo -en "\033[0;34m" #blue text
  61. cat $TMP
  62. echo -e "\033[0m" #unset blue text
  63. echo
  64. echo -e "If not hit ENTER to quit without writing the file or \
  65. \nhit \"W\" and ENTER to write the file and exit."
  66. read writeit
  67. case $writeit in
  68. w|W)cat $TMP > $TARGET/${thename}.desktop # writes the file
  69. echo "File is written to $TARGET/${thename}.desktop." ;;
  70. *)echo "Not writing file." ;;
  71. esac
  72. rm $TMP
  73. exit 0
  74. }
  75. case "$@" in
  76. -h|-*help)usage_func;;
  77. "")interactive ;;
  78. *)thename=$1
  79. #echo "$@"
  80. option=`echo "$@"|sed -e "s'$thename''" \
  81. -e "s'^ ''" \
  82. -e 's#"#\\"#g'`
  83. [ "$thename" = "$option" ] && option=
  84. desktop_func
  85. cat $TMP > $TARGET/${thename}.desktop # writes the file
  86. rm $TMP
  87. esac