Advertisement
Guest User

emacsclient script

a guest
Nov 18th, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.13 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ############## LICENSE #################
  4.  
  5. # This is free and unencumbered software released into the public domain.
  6.  
  7. # Anyone is free to copy, modify, publish, use, compile, sell, or
  8. # distribute this software, either in source code form or as a compiled
  9. # binary, for any purpose, commercial or non-commercial, and by any
  10. # means.
  11.  
  12. # In jurisdictions that recognize copyright laws, the author or authors
  13. # of this software dedicate any and all copyright interest in the
  14. # software to the public domain. We make this dedication for the benefit
  15. # of the public at large and to the detriment of our heirs and
  16. # successors. We intend this dedication to be an overt act of
  17. # relinquishment in perpetuity of all present and future rights to this
  18. # software under copyright law.
  19.  
  20. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  23. # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  24. # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  25. # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  26. # OTHER DEALINGS IN THE SOFTWARE.
  27.  
  28. # For more information, please refer to <https://unlicense.org>
  29.  
  30.  
  31.  
  32. # note: emacsclient args
  33. # -c: make new frame
  34. # -n: don't block terminal command was run in
  35. # -a: with an empty string, starts emacs daemon if it's not already running
  36.  
  37. FRAME=true
  38. # query emacs to see if we've got a frame already
  39. emacsclient -n -e "(if (> (length (frame-list)) 1) 't)" | grep -q t
  40. if [ "$?" = "1" ];
  41. then
  42.   FRAME=false
  43. fi
  44.  
  45. FILE=""
  46. if [ -t 0 ]; then
  47.   # running interactively
  48.   FILE=$@
  49. else
  50.   # probably being run via a pipe (e.g. echo filename > SCRIPT_NAME)
  51.   read -r line
  52.   FILE=$line
  53. fi
  54.  
  55. if [ -z "$FILE" ]; then
  56.   # no filename given
  57.   if [[ "$FRAME" == true ]]; then
  58.     emacsclient -ne "(make-frame)"
  59.   else
  60.     emacsclient -cna ""
  61.   fi
  62. else
  63.   # given a filename
  64.   if [[ "$FRAME" == true ]]; then
  65.     emacsclient -na "" "$FILE"
  66.   else
  67.     emacsclient -cna "" "$FILE"
  68.   fi
  69. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement