diff options
author | William Carroll <wpcarro@gmail.com> | 2017-06-13T15·33-0400 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2017-06-13T15·33-0400 |
commit | 8fff1ba8905256ba8d24c0ae47b5da0eb4efc066 (patch) | |
tree | f0828dd229d92d33aba07655f1f2a4fe27c03da7 | |
parent | 6b3d011491bf03033f5e008792d82bc32b1976ea (diff) |
Better integrates CLI and Emacsclient
-rwxr-xr-x | bins/bin/create-shell-pager.sh | 7 | ||||
-rw-r--r-- | bins/setup_bins.sh | 3 | ||||
-rw-r--r-- | configs/.zsh_profile | 7 | ||||
-rw-r--r-- | emacs/index.sh | 24 | ||||
-rw-r--r-- | emacs/wc-helper-functions.lisp | 42 | ||||
-rw-r--r-- | install.sh | 10 |
6 files changed, 88 insertions, 5 deletions
diff --git a/bins/bin/create-shell-pager.sh b/bins/bin/create-shell-pager.sh new file mode 100755 index 000000000000..a0f42cfd2411 --- /dev/null +++ b/bins/bin/create-shell-pager.sh @@ -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\")" diff --git a/bins/setup_bins.sh b/bins/setup_bins.sh new file mode 100644 index 000000000000..5f989cb80741 --- /dev/null +++ b/bins/setup_bins.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env zsh + +ln -s $HOME/pc_settings/bins/bin/* ~/bin diff --git a/configs/.zsh_profile b/configs/.zsh_profile index 93721b70f4a5..f533036acf9f 100644 --- a/configs/.zsh_profile +++ b/configs/.zsh_profile @@ -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 diff --git a/emacs/index.sh b/emacs/index.sh new file mode 100644 index 000000000000..b7bfd6962011 --- /dev/null +++ b/emacs/index.sh @@ -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 +} diff --git a/emacs/wc-helper-functions.lisp b/emacs/wc-helper-functions.lisp index 1d81115e3905..18c7a67e39bd 100644 --- a/emacs/wc-helper-functions.lisp +++ b/emacs/wc-helper-functions.lisp @@ -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")) diff --git a/install.sh b/install.sh index 302245f141e8..87571d51c55d 100644 --- a/install.sh +++ b/install.sh @@ -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 |