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", "%o", "%p", "%r", "%s" and "%y"
format specifiers are replaced by the respective awk,
hexdump, ls, od, perl, readlink, stat and python
commands. "%n" is replaced by "2>/dev/null", and "%t" is
replaced by a temporary file name. If VEC is nil, the respective
local commands are used. If there is a format specifier which
cannot be expanded, this function returns nil.
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\", \"%o\", \"%p\", \"%r\", \"%s\" and \"%y\"
format specifiers are replaced by the respective `awk',
`hexdump', `ls', `od', `perl', `readlink', `stat' and `python'
commands. \"%n\" is replaced by \"2>/dev/null\", and \"%t\" is
replaced by a temporary file name. If VEC is nil, the respective
local commands are used. If there is a format specifier which
cannot be expanded, this function returns nil."
(if (not (string-match-p
(tramp-compat-rx (| bol (not "%")) "%" (any "ahlnoprsty")) script))
script
(catch 'wont-work
(let ((awk (when (string-match-p
(tramp-compat-rx (| bol (not "%")) "%a") script)
(or
(if vec (tramp-get-remote-awk vec) (executable-find "awk"))
(throw 'wont-work nil))))
(hdmp (when (string-match-p
(tramp-compat-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
(tramp-compat-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))))
(ls (when (string-match-p
(tramp-compat-rx (| bol (not "%")) "%l") script)
(format "%s %s"
(or (tramp-get-ls-command vec)
(throw 'wont-work nil))
(tramp-sh--quoting-style-options vec))))
(od (when (string-match-p
(tramp-compat-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
(tramp-compat-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
(tramp-compat-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
(tramp-compat-rx (| bol (not "%")) "%r") script)
(or
(if vec
(tramp-get-remote-readlink vec)
(executable-find "readlink"))
(throw 'wont-work nil))))
(stat (when (string-match-p
(tramp-compat-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
(tramp-compat-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 ?h hdmp ?l ls ?n dev ?o od ?p perl
?r readlink ?s stat ?t tmp ?y python))))))