Created
August 21, 2011 17:42
-
-
Save tavisrudd/1160897 to your computer and use it in GitHub Desktop.
fuzzy completion search for gentoo ebuilds in elisp (using ido)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This is a wrapper around ssh so multi-term / emacs e-term will work | |
# well with remote shells. | |
term_name=$1 | |
shift | |
screen -m -e^Uu -S $term_name /usr/bin/ssh $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'ido) | |
(setq ido-enable-flex-matching t) | |
;;; ... skipping more ido config | |
(defun dss/gentoo-eix-choice (prefix) | |
(interactive "sPattern:") | |
(let* ((eix-list | |
(split-string | |
(shell-command-to-string | |
(concat | |
"eix --only-names '" prefix "'")))) | |
(choice (ido-completing-read "Which package: " eix-list))) | |
choice)) | |
;;; and some uses of it: | |
(defun dss/gentoo-flagedit (pat) | |
(interactive "sPattern:") | |
(let ((choice (dss/gentoo-eix-choice pat))) | |
(dss/remote-term "root@localhost" (concat "flaggie " choice " +~amd64")))) | |
(defun dss/gentoo-emerge (pat) | |
(interactive "sPattern:") | |
(let ((choice (dss/gentoo-eix-choice pat))) | |
(dss/remote-term "root@localhost" (concat "emerge -avuDN " choice)))) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;; which require this stuff: | |
(require 'multi-term) | |
(defun dss/remote-term (host &optional command term-command) | |
(interactive) | |
(let* (term-buffer | |
(index 1) | |
(term-command (or term-command "eterm-ssh")) | |
term-name) | |
(while (buffer-live-p | |
(get-buffer (format "*%s<%s>*" host index))) | |
(setq index (1+ index))) | |
(setq term-name (format "%s<%s>" host index)) | |
(setq term-buffer | |
(make-term term-name term-command nil term-name host)) | |
(set-buffer term-buffer) | |
;; Internal handle for `multi-term' buffer. | |
(multi-term-internal) | |
;; Switch buffer | |
(switch-to-buffer term-buffer) | |
(sleep-for 1) | |
(dss/term-setup-tramp) | |
(if command | |
(term-send-raw-string command)))) | |
(defun dss/term-setup-tramp () | |
"Setup ansi-term/tramp remote directory tracking | |
NOTE: this appears to have some sort of timing bug in it and doesn't always work" | |
(interactive) | |
(term-send-raw-string | |
(concat " | |
function eterm_set_variables { | |
local emacs_host=\"" (car (split-string (system-name) "\\.")) "\" | |
if [[ $TERM == \"eterm-color\" ]]; then | |
if [[ ${HOSTNAME-$(hostname)} != \"$emacs_host\" ]]; then | |
echo -e \"\\033AnSiTu\" ${TRAMP_USERNAME-$(whoami)} | |
echo -e \"\\033AnSiTh\" ${TRAMP_HOSTNAME-$(hostname)} | |
fi | |
echo -e \"\\033AnSiTc\" $(pwd) | |
elif [[ $TERM == \"screen\" || $TERM == \"screen-256color\" ]]; then | |
if [[ ${HOSTNAME-$(hostname)} != \"$emacs_host\" ]]; then | |
echo -e \"\\033P\\033AnSiTu\\033\\\\\" ${TRAMP_USERNAME-$(whoami)} | |
echo -e \"\\033P\\033AnSiTh\\033\\\\\" ${TRAMP_HOSTNAME-$(hostname)} | |
fi | |
echo -e \"\\033P\\033AnSiTc\\033\\\\\" $(pwd) | |
fi | |
} | |
function eterm_tramp_init { | |
for temp in cd pushd popd; do | |
alias $temp=\"eterm_set_cwd $temp\" | |
done | |
# set hostname, user, and cwd now | |
eterm_set_variables | |
} | |
function eterm_set_cwd { | |
$@ | |
eterm_set_variables | |
} | |
eterm_tramp_init | |
export -f eterm_tramp_init | |
export -f eterm_set_variables | |
export -f eterm_set_cwd | |
clear | |
echo \"tramp initialized\" | |
"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment