Function: tramp-expand-script
tramp-expand-script is a byte-compiled function defined in
tramp-sh.el.gz.
Signature
(tramp-expand-script VEC SCRIPT)
Documentation
Expand SCRIPT with remote files or commands.
"%a", "%h", "%l", "%m", "%o", "%p", "%q", "%r", "%s"
and "%y" format specifiers are replaced by the respective awk,
hexdump, ls, test, od', perl, test -e, readlink, stat and
python commands.
"%b" is replaced by a call of "tramp_bundle_read_file-names", "%k"
is replaced by a call of "tramp_shell_print_quoted_string", "%n" is
replaced by "2>/dev/null", and "%t" is replaced by a temporary file
name.
"%%" is replaced by "%". If one of the format specifiers cannot be
expanded, this function returns nil. If there are only other format
specifiers, SCRIPT is returned unchanged.
If VEC is nil, the respective local commands are used.
Source Code
;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
;;; Internal Functions:
(defun tramp-expand-script (vec script)
"Expand SCRIPT with remote files or commands.
\"%a\", \"%h\", \"%l\", \"%m\", \"%o\", \"%p\", \"%q\", \"%r\", \"%s\"
and \"%y\" format specifiers are replaced by the respective `awk',
`hexdump', `ls', `test', od', `perl', `test -e', `readlink', `stat' and
`python' commands.
\"%b\" is replaced by a call of \"tramp_bundle_read_file-names\", \"%k\"
is replaced by a call of \"tramp_shell_print_quoted_string\", \"%n\" is
replaced by \"2>/dev/null\", and \"%t\" is replaced by a temporary file
name.
\"%%\" is replaced by \"%\". If one of the format specifiers cannot be
expanded, this function returns nil. If there are only other format
specifiers, SCRIPT is returned unchanged.
If VEC is nil, the respective local commands are used."
(catch 'wont-work
(let ((awk (when (string-match-p (rx (| bol (not "%")) "%a") script)
(or
(if vec (tramp-get-remote-awk vec) (executable-find "awk"))
(throw 'wont-work nil))))
(bundle (when (string-match-p (rx (| bol (not "%")) "%b") script)
(tramp-maybe-send-script
vec tramp-bundle-read-file-names
"tramp_bundle_read_file_names")
"tramp_bundle_read_file_names"))
(hdmp (when (string-match-p (rx (| bol (not "%")) "%h") script)
(or
(if vec (tramp-get-remote-hexdump vec)
(executable-find "hexdump"))
(throw 'wont-work nil))))
(dev (when (string-match-p (rx (| bol (not "%")) "%n") script)
(or
(if vec (concat "2>" (tramp-get-remote-null-device vec))
(if (eq system-type 'windows-nt) ""
(concat "2>" null-device)))
(throw 'wont-work nil))))
(lispy (when (string-match-p (rx (| bol (not "%")) "%k") script)
(tramp-maybe-send-script
vec tramp-shell-print-quoted-string
"tramp_shell_print_quoted_string")
"tramp_shell_print_quoted_string"))
(ls (when (string-match-p (rx (| bol (not "%")) "%l") script)
(format "%s %s"
(or (tramp-get-ls-command vec)
(throw 'wont-work nil))
(tramp-sh--quoting-style-options vec))))
(test (when (string-match-p (rx (| bol (not "%")) "%m") script)
(or (tramp-get-test-command vec)
(throw 'wont-work nil))))
(test-e (when (string-match-p (rx (| bol (not "%")) "%q") script)
(or (tramp-get-file-exists-command vec)
(throw 'wont-work nil))))
(od (when (string-match-p (rx (| bol (not "%")) "%o") script)
(or (if vec (tramp-get-remote-od vec) (executable-find "od"))
(throw 'wont-work nil))))
(perl (when (string-match-p (rx (| bol (not "%")) "%p") script)
(or
(if vec
(tramp-get-remote-perl vec) (executable-find "perl"))
(throw 'wont-work nil))))
(python (when (string-match-p (rx (| bol (not "%")) "%y") script)
(or
(if vec
(tramp-get-remote-python vec)
(executable-find "python"))
(throw 'wont-work nil))))
(readlink (when (string-match-p (rx (| bol (not "%")) "%r") script)
(format "%s %s"
(or
(if vec
(tramp-get-remote-readlink vec)
(executable-find "readlink"))
(throw 'wont-work nil))
"--canonicalize-missing")))
(stat (when (string-match-p (rx (| bol (not "%")) "%s") script)
(or
(if vec
(tramp-get-remote-stat vec) (executable-find "stat"))
(throw 'wont-work nil))))
(tmp (when (string-match-p (rx (| bol (not "%")) "%t") script)
(or
(if vec
(tramp-file-local-name (tramp-make-tramp-temp-name vec))
(tramp-compat-make-temp-name))
(throw 'wont-work nil)))))
(format-spec
script
(format-spec-make
?a awk ?b bundle ?h hdmp ?k lispy ?l ls ?m test ?n dev ?o od
?p perl ?q test-e ?r readlink ?s stat ?t tmp ?y python)))))