linux - How to launch a shell script with an emacs keybinding, passing the word under the cursor as a variable -


executing script below on osx via emacs, didn't work, got permission denied message, answer question solved problem: https://stackoverflow.com/a/12276562/912475

tldr: how can set system automatically pass word under cursor in emacs directly shell script variable , run script?

i've created rudimentary system "linking" folders plain text files in robust way. uses timestamp that's generated script , set "value" of clipboard. clipboard, timestamp pasted txt related notes , name field of folder.

to find folders when reading txt use emacs function keybinding makes possible copy timestamp (as word, it's numbers) clipboard , search in spotlight (on osx). i'd instead automatically launch shell script searches directory name ends string , opens it. have script that, don't know how tie elisp function , shell script together. i'd appreciate solution works on either osx , linux (i use both). easy "port" solution works on either 1 use other.

this emacs function copying word under cursor:

;;; function copying word under cursor http://www.emacswiki.org/emacs/copywithoutselection     (global-set-key (kbd "c-c o")         (quote copy-word))       (defun copy-word (&optional arg)       "copy words @ point kill-ring"        (interactive "p")        (copy-thing 'backward-word 'forward-word arg)        ;;(paste-to-mark arg)      ) 

this script find , open directory name ends timestamp:

#!/bin/bash path=/opt/local/bin:/opt/local/sbin:$path #need make gnu coreutils work on osx file_number="20130812193913" path_to_open=$(gfind ~/x/ | grep -e $file_number$) # $ means end of line, makes possible search directories without finding content open "${path_to_open}" 

an edited version of script accepts arguments commandline this:

me$ sh script_path.sh 20130812193913 

the script:

#!/bin/bash path=/opt/local/bin:/opt/local/sbin:$path #need make gnu coreutils work on osx file_number=$1 echo $file_number path_to_open=$(gfind ~/x/ | grep -e $file_number$) # $ means end of line, makes possible search directories without finding content open "${path_to_open}" 

see: http://www.bashguru.com/2009/11/how-to-pass-arguments-to-shell-script.html

you try this:

(defvar script-name "/foo/bar/my-script")  (defun call-my-script-with-word ()   (interactive)   (shell-command    (concat script-name             " "            (thing-at-point 'word)))) (global-set-key (kbd "c-c o") 'call-my-script-with-word) 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -