20 Commits

Author SHA1 Message Date
44ae82b5d6 temp! 2022-02-10 23:05:16 +00:00
5d1f53e6b1 Add prompt support for distrobox 2022-01-14 19:51:33 +00:00
8628448d5d Also alias batcat 2022-01-07 15:55:25 +00:00
b1129a164d Don't use which, use command -v instead 2021-12-15 00:22:04 +00:00
5e6ad90a98 Fix package become & use package name lists 2021-12-15 00:21:28 +00:00
3e743d6757 Create directories 2021-12-15 00:07:02 +00:00
63b7170ccb Fix bug in almostontop that truncated long prompts
Add collection of cursor line immediately after the previous command
completes and use this when calculating the number of lines required to
move the screen in order to display only the latest prompt.
2021-12-07 17:06:39 +00:00
3978f2b1c2 Prompt to run $ command if present 2021-11-22 23:12:51 +00:00
709c65ce7b Move main.yaml to tasks.yaml 2021-11-19 22:04:42 +00:00
782589ff81 Add unzip to Debian package list 2021-11-06 15:29:37 +00:00
cc5840fd20 Start using Ansible for config management 2021-11-05 14:07:45 +00:00
014dadecb2 Only set WGETRC when ~/.config/wgetrc exists 2021-08-03 14:19:08 +01:00
b89428cd32 Extract .tar.xz properly on Linux 2021-07-27 23:52:47 +01:00
85b531e773 Use a different bat theme
Don't use Solarized Dark theme because not all `bat` installs make it
available.
2021-07-14 21:21:58 +01:00
acfd0cdee4 More escape sequence utilities
* Add `tmux-dcs-passthrough` to passthrough escape sequences tmux
  doesn't understand.
* Add `notify` to post a notification via the terminal emulator.
2021-06-17 22:46:14 +01:00
4561adf530 Teach ipython to use XDG base dirs 2021-06-17 22:46:14 +01:00
a7a8d7da8f Properly extract .tar.xz on macOS 2021-06-17 22:46:14 +01:00
20a3911ab7 Ensure pynvim is installed in autoenv's 2021-04-17 17:39:57 +01:00
ff87027cf7 Fix a long standing issue with fresh_almostontop()
Up till now setting the `-a` flag of the `prompt_fresh_setup` theme
resulted in duplicate prompts being printed to the terminal. The first,
the interactive prompt with syntax highlighting, and a second after a
call to the `clear` command without syntax highlighting. This patch
replaces the old implementation with one which does not use `clear`.
Instead it queries the terminal for the current cursor position, then
uses this to move to the bottom of the terminal, print a number of new
lines to move the stale command output off screen, and finally move
almost back to the top ready for the invoked command to print it's
output.
2021-03-20 00:03:20 +00:00
b4d22fc49f Remove guake workaround 2021-03-09 19:19:08 +00:00
9 changed files with 188 additions and 84 deletions

6
$ Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env zsh
read -p "Are you sure? [y/N]: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
exec "$@"
fi

View File

@@ -1,47 +0,0 @@
---
- location: ~/.config/zsh
- apt:
- zsh
- zsh-doc
- pinentry-curses
- brew:
- zsh
- pacman:
- zsh
- dnf:
- util-linux-user
- zsh
- command:
- install: sudo chsh -s `which zsh` $USER
remove: sudo chsh -s `which bash` $USER
- symlink:
- {src: zlogin, dst: ~/.zlogin}
- {src: zlogout, dst: ~/.zlogout}
- {src: zprofile, dst: ~/.zprofile}
- {src: zshenv, dst: ~/.zshenv}
- {src: zshrc, dst: ~/.zshrc}
- src: prompt_fresh_setup
dst: ~/.local/share/zsh/site-functions/prompt_fresh_setup
- src: build/_build-dir
dst: ~/.local/share/zsh/site-functions/_build-dir
- src: sandbox/_sandbox
dst: ~/.local/share/zsh/site-functions/_sandbox
- src: layout/_layout
dst: ~/.local/share/zsh/site-functions/_layout
- src: notes/_note
dst: ~/.local/share/zsh/site-functions/_note
- repo:
- https://github.com/zsh-users/zsh-autosuggestions.git
- https://github.com/zsh-users/zsh-history-substring-search.git
- https://github.com/zsh-users/zsh-syntax-highlighting.git
- https://github.com/zsh-users/zsh-completions.git
- https://github.com/junegunn/fzf.git
- command:
- fzf/install --bin
- symlink:
- {src: fzf/bin/fzf, dst: ~/.local/bin/fzf}
- {src: fzf/bin/fzf-tmux, dst: ~/.local/bin/fzf-tmux}
- {src: cmake-uninstall, dst: ~/.local/bin/cmake-uninstall}
- command:
- zsh update-completion-links.zsh
- message: zsh will be the default prompt after next login

View File

@@ -2,15 +2,13 @@
<!-- TODO: GIF --> <!-- TODO: GIF -->
## [conduit][conduit] ## Ansible
Simple, local, configuration manager. To install this Zsh configuration:
Installation of the configuration files in this repository is orchestrated by ```console
[conduit][conduit] as defined in the [`.conduit.yaml`](.conduit.yaml) file. This $ ansible-playbook main.yaml --ask-become-pass
includes [Zsh][zsh] package installs, setting [Zsh][zsh] as the users default ```
shell, and symbolic linking file such as [`zshrc`](zshrc) to `~/.zshrc`, and
cloning plugin repositories. The repository is cloned to `~/.config/zsh`.
## Prompt ## Prompt

View File

@@ -103,6 +103,7 @@ commands:
_autoenv_authorized $PWD/.enter yes _autoenv_authorized $PWD/.enter yes
_autoenv_authorized $PWD/.exit yes _autoenv_authorized $PWD/.exit yes
_autoenv_enter $PWD _autoenv_enter $PWD
pip install pynvim
;; ;;
*) # Invalid arguments, show help then error. *) # Invalid arguments, show help then error.

View File

@@ -27,9 +27,11 @@ prompt_fresh_setup() {
if [ $almostontop -eq 1 ]; then if [ $almostontop -eq 1 ]; then
# Hook to clear the screen then prints the prompt with previous command at # Hook to clear the screen then prints the prompt with previous command at
# the top of the screen. # the top of the screen.
add-zsh-hook preexec fresh_almostontop add-zsh-hook precmd fresh_almostontop_precmd
add-zsh-hook preexec fresh_almostontop_preexec
else else
add-zsh-hook -d preexec fresh_almostontop add-zsh-hook -d preexec fresh_almostontop_preexec
add-zsh-hook -d precmd fresh_almostontop_precmd
fi fi
[ $recompile -eq 1 ] && prompt_cleanup [ $recompile -eq 1 ] && prompt_cleanup
@@ -42,7 +44,7 @@ prompt_fresh_setup() {
fi fi
local userhost=$USER local userhost=$USER
if [ "$SSH_CONNECTION" != "" ]; then if [ "$SSH_CONNECTION" != "" ] || [ "$DISTROBOX_ENTER_PATH" != "" ]; then
local user="$user@%{%F{244}%}%M%{%f%}" local user="$user@%{%F{244}%}%M%{%f%}"
local userhost="$userhost@`hostname`" local userhost="$userhost@`hostname`"
fi fi
@@ -128,10 +130,43 @@ fresh_line_one() {
print -P "$time_stamp $directory$git$py$docker$result" print -P "$time_stamp $directory$git$py$docker$result"
} }
fresh_almostontop() { # Executed before each prompt.
clear fresh_almostontop_precmd() {
fresh_line_one # CSI ESC[6n gets the cursor position in the form ESC[<row>;<column>R
print -P "$PROMPT"'$1' printf "\033[6n"
# Discard prefix delimited by [
read -s -d [
# Store the <row> delimited by ; in row_before
read -s -d \; row_before
# Discard suffix delimted by R otherwise it is output to the tty
read -s -d R
}
# Executed just after a command has been read and is about to be executed.
fresh_almostontop_preexec() {
# CSI ESC[6n gets the cursor position in the form ESC[<row>;<column>R
printf "\033[6n"
# Discard prefix delimited by [
read -s -d [
# Store the <row> delimited by ; in row
read -s -d \; row
# Discard suffix delimted by R otherwise it is output to the tty
read -s -d R
# Move the cursor to the bottom of the terminal
# CSI ESC[<num>B moves the cursor down <num> lines
let "down = $LINES - $row"
printf "\033[${down}B"
# Calculate the number of lines in the prompt
let "prompt_lines = ($row - $row_before) + 2"
# Print new lines to push the old command out of view
let "new = $row - $prompt_lines"
for (( i = 0; i < $new; i++ )); do
printf "\n"
done
# Move the cursor to the line below the prompt
# CSI ESC[<num>A moves the cursor up <num> lines
let "up = $LINES - $prompt_lines"
printf "\033[${up}A"
} }
fresh_compile_git_prompt() { fresh_compile_git_prompt() {

91
tasks.yaml Normal file
View File

@@ -0,0 +1,91 @@
---
- name: zsh install packages
become: '{{package_become}}'
package:
name: zsh
state: present
- name: zsh install Debian packages
when: ansible_os_family == "Debian"
become: true
apt:
name:
- zsh-doc
- pinentry-curses
- unzip
state: present
- name: zsh clone plugin repos
git:
repo: '{{item.repo}}'
dest: '{{item.dest}}'
with_items:
- repo: https://github.com/zsh-users/zsh-autosuggestions.git
dest: ~/.config/zsh/zsh-autosuggestions
- repo: https://github.com/zsh-users/zsh-history-substring-search.git
dest: ~/.config/zsh/zsh-history-substring-search
- repo: https://github.com/zsh-users/zsh-syntax-highlighting.git
dest: ~/.config/zsh/zsh-syntax-highlighting
- repo: https://github.com/zsh-users/zsh-completions.git
dest: ~/.config/zsh/zsh-completions
- repo: https://github.com/junegunn/fzf.git
dest: ~/.config/zsh/fzf
- name: zsh install fzf binaries
command:
cmd: ~/.config/zsh/fzf/install --bin
creates: ~/.config/zsh/fzf/bin/fzf
- name: zsh create directories
file:
state: directory
dest: '{{item}}'
with_items:
- ~/.local/bin
- ~/.local/share/zsh/site-functions
- name: zsh create symbolic links
file:
state: link
src: '{{item.src}}'
dest: '{{item.dest}}'
with_items:
- src: ~/.config/zsh/zlogin
dest: ~/.zlogin
- src: ~/.config/zsh/zlogout
dest: ~/.zlogout
- src: ~/.config/zsh/zprofile
dest: ~/.zprofile
- src: ~/.config/zsh/zshenv
dest: ~/.zshenv
- src: ~/.config/zsh/zshrc
dest: ~/.zshrc
- src: ~/.config/zsh/prompt_fresh_setup
dest: ~/.local/share/zsh/site-functions/prompt_fresh_setup
- src: ~/.config/zsh/build/_build-dir
dest: ~/.local/share/zsh/site-functions/_build-dir
- src: ~/.config/zsh/sandbox/_sandbox
dest: ~/.local/share/zsh/site-functions/_sandbox
- src: ~/.config/zsh/layout/_layout
dest: ~/.local/share/zsh/site-functions/_layout
- src: ~/.config/zsh/notes/_note
dest: ~/.local/share/zsh/site-functions/_note
- src: ~/.config/zsh/fzf/bin/fzf
dest: ~/.local/bin/fzf
- src: ~/.config/zsh/fzf/bin/fzf-tmux
dest: ~/.local/bin/fzf-tmux
- src: ~/.config/zsh/cmake-uninstall
dest: ~/.local/bin/cmake-uninstall
- src: ~/.config/zsh/$
dest: ~/.local/bin/$
- name: zsh get absolute path
shell: command -v zsh
register: zsh
changed_when: false
- name: zsh set default shell
user:
name: '{{lookup("env", "USER")}}'
shell: '{{zsh.stdout}}'
become: true

View File

@@ -15,19 +15,39 @@ elif which xclip &> /dev/null; then
fi fi
# Abstract different ways to paste from the clipboard. # Abstract different ways to paste from the clipboard.
if [ "`uname`" = "Darwin" ]; then # TODO: Use OSC-52 to get the clipboard, not widely supported though
if [ -n "$SSH_CONNECTION" ]; then
# Use OSC-52 to get the clipboard
alias paste='printf "\033]52;c;?\a"'
elif [ "`uname`" = "Darwin" ]; then
# Use pbpaste to get the clipboard
alias paste='pbpaste' alias paste='pbpaste'
elif which xclip &> /dev/null; then elif which xclip &> /dev/null; then
# Use xclip to get the clipboard
alias paste='xclip -selection c -o' alias paste='xclip -selection c -o'
fi fi
# Passthrough an escape sequences tmux doesn't know about.
tmux-dcs-passthrough() {
if [ -n "$TMUX" ]; then
printf "\x1bPtmux;\x1b$1\x1b\\"
else
printf "$1"
fi
}
# OSC 9 - Post a notification - supported by iTerm2, maybe others?
notify() {
tmux-dcs-passthrough "\x1b]9;$*\x7"
}
# Detect the type and extract an archive file. # Detect the type and extract an archive file.
extract() { extract() {
if [ -f $1 ]; then if [ -f $1 ]; then
case $1 in case $1 in
*.tar.bz2) tar xvjf $1 ;; *.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;; *.tar.gz) tar xvzf $1 ;;
*.tar.xz) gunzip $1 ;; *.tar.xz) [ `"uname"` = "Darwin" ] && tar xvJf $1 || tar xf $1 ;;
*.bz2) bunzip2 $1 ;; *.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;; *.rar) unrar x $1 ;;
*.gz) gunzip $1 ;; *.gz) gunzip $1 ;;
@@ -49,8 +69,11 @@ if which bat &> /dev/null; then
# Both --theme and --color can be specified multiple times and will override # Both --theme and --color can be specified multiple times and will override
# these defaults. # these defaults.
bat() { bat() {
command bat --theme='Solarized (dark)' --color always \ command bat --theme='TwoDark' --color always --paging auto "$@"
--paging always --pager 'less -R' "$@" }
elif which batcat &> /dev/null; then
bat() {
command batcat --theme='TwoDark' --color always --paging auto "$@"
} }
fi fi

3
zshenv
View File

@@ -81,6 +81,7 @@ which pinentry-curses &> /dev/null && \
export LPASS_PINENTRY=pinentry-curses export LPASS_PINENTRY=pinentry-curses
# Teach these some XDG Base Directory Spec manners # Teach these some XDG Base Directory Spec manners
export IPYTHONDIR=$HOME/.config/ipython
which cargo &> /dev/null && \ which cargo &> /dev/null && \
export CARGO_HOME=$HOME/.local/share/cargo export CARGO_HOME=$HOME/.local/share/cargo
if which ccache &> /dev/null; then if which ccache &> /dev/null; then
@@ -97,5 +98,5 @@ which rustup &> /dev/null && \
export RUSTUP_HOME=$HOME/.local/share/rustup export RUSTUP_HOME=$HOME/.local/share/rustup
export PYLINTHOME=$HOME/.cache/pylint export PYLINTHOME=$HOME/.cache/pylint
# TODO: terminfo # TODO: terminfo
which wget &> /dev/null && \ [ -f $HOME/.config/wgetrc ] &&
export WGETRC=$HOME/.config/wgetrc export WGETRC=$HOME/.config/wgetrc

8
zshrc
View File

@@ -138,17 +138,13 @@ if [[ `uname` = Linux ]]; then
[[ -n ${key[End]} ]] && bindkey "${key[End]}" end-of-line [[ -n ${key[End]} ]] && bindkey "${key[End]}" end-of-line
fi fi
# Get the shells parent process name.
ppid_name() { echo $(ps -p $(ps -p $(echo $$) -o ppid=) -o comm=) }
# Enable changing cursor shape based on vi mode # Enable changing cursor shape based on vi mode
if [ "$ITERM_PROFILE" != "" ] && [ "$TMUX" = "" ]; then if [ "$ITERM_PROFILE" != "" ] && [ "$TMUX" = "" ]; then
# iTerm2 cursor shape escape sequences outside tmux # iTerm2 cursor shape escape sequences outside tmux
cursor_block="\e]50;CursorShape=0\C-G" cursor_block="\e]50;CursorShape=0\C-G"
cursor_line="\e]50;CursorShape=1\C-G" cursor_line="\e]50;CursorShape=1\C-G"
elif [ "$(ppid_name)" != "python2" ]; then else
# iTerm2 inside tmux or VTE compatible cursor shape escape sequences, # iTerm2 inside tmux or VTE compatible cursor shape escape sequences.
# exclude Guake even though it's VTE based it doesn't like these
cursor_block="\e[2 q" cursor_block="\e[2 q"
cursor_line="\e[6 q" cursor_line="\e[6 q"
fi fi