Better integrates CLI and Emacsclient

This commit is contained in:
William Carroll 2017-06-13 11:33:16 -04:00
parent 6b3d011491
commit 8fff1ba890
6 changed files with 88 additions and 5 deletions

7
bins/bin/create-shell-pager.sh Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
file=$(mktemp -t "$USER-"XXXXXXXX.emacs-pager) || exit 127
trap 'rm -f "$file"' EXIT
trap 'exit 255' HUP INT QUIT TERM
cat "$@" >"$file"
emacsclient -e "(wc/open-in-pager \"$file\")"

3
bins/setup_bins.sh Normal file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env zsh
ln -s $HOME/pc_settings/bins/bin/* ~/bin

View file

@ -24,11 +24,11 @@ echo "Welcome back, $USER"
# display the space available on each mounted Volume
df -hl
# use vi bindings for terminal input
# set -o vi
# use emacs bindings (default) for terminal input
set -o emacs
# aliases
source $HOME/pc_settings/aliases.sh
@ -38,6 +38,9 @@ source $HOME/pc_settings/functions/index.sh
# setup keybindings for history functions
source $HOME/pc_settings/scripts/setup_keybindings.sh
# setup emacs + shell configuration
source $HOME/pc_settings/emacs/index.sh
# BEGIN: bindkeys
bindkey "^R" history-incremental-search-backward

24
emacs/index.sh Normal file
View file

@ -0,0 +1,24 @@
#!/usr/bin/env zsh
if [ -n "$INSIDE_EMACS" ]; then
export PAGER="create-shell-pager.sh"
else
export PAGER="less"
fi
if [ -n "$INSIDE_EMACS" ]; then
export EDITOR="emacsclient"
else
export EDITOR=$(which vim)
fi
man () {
if [ -n "$INSIDE_EMACS" ]; then
emacsclient -e "(man \"$1\")"
else
command man "$1"
fi
}

View file

@ -1,3 +1,36 @@
(defun wc/open-in-pager (file)
(find-file file)
(emacs-pager-mode))
(defvar emacs-pager-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "q") 'kill-this-buffer)
map)
"Keymap for emacs pager mode.")
(defcustom emacs-pager-max-line-coloring 500
"Maximum number of lines to ansi-color. If performance is bad when
loading data, reduce this number"
:group 'emacs-pager)
(define-derived-mode emacs-pager-mode fundamental-mode "Pager"
"Mode for viewing data paged by emacs-pager"
(setq-local make-backup-files nil)
(ansi-color-apply-on-region (goto-char (point-min))
(save-excursion
(forward-line emacs-pager-max-line-coloring)
(point)))
(setq buffer-name "*pager*")
(set-buffer-modified-p nil)
(read-only-mode)
(evil-define-key 'normal emacs-pager-mode-map
(kbd "q") 'kill-this-buffer
(kbd "ESC") 'kill-this-buffer))
(defun wc/projectile-shell-pop ()
"Opens `ansi-term' at the project root according to Projectile."
(interactive)
@ -29,6 +62,15 @@
:buffer "*helm projectile terminals*"))
(defun wc/git-changed-files ()
"Lists active terminal buffers."
(interactive)
(helm :sources (helm-build-in-buffer-source "test1"
:data ((lambda () (shell-command-to-string "wc-git-changed-files")))
:action 'term-send-raw-string)
:buffer "*helm git changed file*"))
(defun wc/shell-history ()
(setq history (shell-command-to-string "history"))
(split-string history "\n"))

View file

@ -1,5 +1,9 @@
#!/usr/bin/env bash
#!/usr/bin/env zsh
# install brew and its packages
. ./install_brew.sh
# install custom bin/ executables to $HOME/bin
source $HOME/pc_settings/bins/setup_bins.sh
# symlink config files
source $HOME/pc_settings/configs/setup_configs.sh