100 Commits

Author SHA1 Message Date
9618713542 Make git-prompt also work in a bash promtp 2022-11-03 21:36:12 +00:00
5a33d2b5ac Add autoenv add=local subcommand
The `add=local` subcommand creates `.local/bin` if it doesn't exit and
then updates the autoenv to add it to `PATH`.
2022-10-26 20:31:51 +01:00
c691d335c0 Disable zsh-history-substring-search highlights 2022-10-11 17:16:23 +01:00
715014ed3d Specify compdump file location to compinit 2022-09-20 22:45:54 +01:00
efcea9e8a5 Change value of WGETRC 2022-09-20 22:45:42 +01:00
ea61bde858 Change sandbox prompt highlight color 2022-07-29 17:45:12 +01:00
a96aa50fbe Add --show option to build-dir command
The new option shows the current build directory, if present.
2022-07-11 13:47:05 +01:00
c61c86e979 Add ~Sandbox hashed directory 2022-06-12 21:03:54 +01:00
8790bc0c4e Use $EDITOR rather the vim directory 2022-03-31 22:13:26 +01:00
b349befbf4 Be explicit about python absolute path
One some distros `virtualenv` still uses a Python 2 executable, I always
set `python` to point to Python 3 so be explicit about getting the
absolute path to `python` when creating a `virtualenv` with `autoenv
add=py`.
2022-03-22 13:29:33 +00:00
74f2dd7dae Fix autoenv add=py .enter when run in subdirectory 2022-03-22 13:29:33 +00:00
a362ab0e04 Prefer nvim over vim for EDITOR, don't use which 2022-02-26 17:22:51 +00:00
a422ab1125 Also install ag 2022-02-19 11:13:39 +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
b694e9cdf5 Add copy and paste aliases to clipboard commands
Interact with the clipboard through the `copy` and `paste` aliases.

`copy` is defined when:

1. An `ssh` connection is detected, using OSC-52.
2. macOS is detected, using `pbcopy`.
3. `xsel` is detected.

`paste` is define when:

1. macOS is detected, using `pbpaste`.
2. `xsel` is detected.
2021-03-02 20:04:33 +00:00
d91d6b3534 Wrap bat with additional arguments 2021-03-02 20:02:30 +00:00
309a8833c8 Make using docker on macOS nicer 2021-02-20 15:36:26 +00:00
c4a91481db Add autoenv reload subcommand
The `autoenv reload` subcommand reloads the current environment.
2021-02-09 16:47:27 +00:00
0b5fc5ad97 Set CMAKE_GENERATOR when ninja is present 2021-01-18 19:11:24 +00:00
258baeba77 Add support for Fedora 2020-12-31 15:55:53 +00:00
b6c11ecdfb Add cmake-uninstall script 2020-09-12 15:47:36 +01:00
92bacb5785 Teach various tools XDG Base Directory spec manners 2020-08-22 10:43:26 +01:00
6935281118 Fix ignore pattern for cloned plugins 2020-08-22 10:42:49 +01:00
6be7ac0e4e Fix cls alias when in tmux on iTerm2 2020-07-31 12:24:43 +01:00
a67649e844 Add frequent-directory function
`frequent-directory` exports and environment variable and creates a hash
directory with the given argument of the form `<name>=<path>`.
2020-07-30 11:24:56 +01:00
01fcdc1863 Update cls to work correctly in Windows Terminal 2020-07-17 23:10:16 +01:00
6d92a82d8c Load autoenv plugin later to make build-dir ready 2020-07-08 16:06:14 +01:00
81657d6f50 Update vim version check for enabling vimdebug 2020-02-06 13:36:05 +00:00
db124794ef Add unversioned brew python links to PATH
The `python` Homebrew package installs unversioned links to Python 3
executables in `/usr/local/opt/python/libexec/bin`. Add this directory
to the `PATH` environment variable when it's present.
2020-01-16 23:25:09 +00:00
ec8675fa86 Use XDG base dirs for ccache 2020-01-14 10:54:24 +00:00
9164432cc2 Don't store less history 2019-12-10 13:26:36 +00:00
39a4d589b3 Change default pylint data storage location 2019-12-10 12:16:44 +00:00
6eec18c98e Set EDITOR to vim if it exists 2019-11-10 13:47:09 +00:00
1cf7e1dcaf Don't send git clone to /dev/null 2019-10-05 19:12:21 +01:00
908ef3efa5 Add autoenv add=py to streamline virtualenvs 2019-10-05 19:11:26 +01:00
4252d06e65 Fix ccache PATH on Manjaro 2019-10-01 22:50:20 +01:00
9854518c76 Fix Home/End on Arch where $key is not auto setup 2019-09-18 22:01:12 +01:00
aab16bd355 Add zsh pacman package 2019-09-17 20:41:26 +01:00
4812d5e564 Don't prompt for sandbox authorization
Automatically approve `.enter`/`.exit` scripts when creating or renaming
sandboxes.
2019-09-10 20:13:10 +01:00
610cae2f57 Check for tmux session in prompt
Before invoking the `tmux` command to unset the vim pane variable first
check that a `tmux` session exists.
2019-09-05 11:22:47 +01:00
a3832ff49e Automatically authorize sandbox .enter/.exit 2019-09-03 21:06:48 +01:00
a2509a88b5 Add git clone support to sandbox create
Partially address #13 by adding the `--git <repo>` option to `sandbox
create`. This enables the quick cloning of a remote repository instead
of doing the tedious dance of creating a sandbox, cloning the remote
repo, deleting the sandbox repo them moving the `.git` directory before
doing a `git reset --hard HEAD`.

Additionally, improve the error messages for all `sandbox` commands,
clean up the completions a little, and use a consistent style in the
scripts.
2019-08-29 00:56:26 +01:00
8997d9cae0 Add zsh-completions
The [zsh-completions](https://github.com/zsh-users/zsh-completions) repo
contains completions for various commands but not all of these are
useful so the `update-completion-links.zsh` script inspects the `PATH`
to determine which of the completions should be symlinked to
`~/.local/share/zsh/site-functions` which resides on the `fpath`.
2019-08-23 21:11:56 +01:00
8526bdb4e3 Export CTEST_OUTPUT_ON_FAILURE=1
When a `ctest` run contains a failed test, actually print the `stdout`
and `stderr` output.
2019-08-22 21:32:15 +01:00
47f821e80a Don't unset tmux option when not in tmux 2019-08-22 21:31:56 +01:00
fcae9e885e Unset the vim navigation flag on prompt redraw
Make using the `@vim$TMUX_PANE` window flag much more robust by
unsetting it every time the zsh prompt is drawn and setting it again
using a `FocusGained` `autocmd` in vim. This removes the need for the
hacky check for zsh in the conditional defined in the `in_vim` variable.
2019-08-16 21:57:33 +01:00
7a8cf750bd Don't apply Begin/End key fix on macOS 2019-06-07 20:07:32 +01:00
7a0c73dabb autoenv: Automatically update autoenv during edit
Fixes #18 by exiting the autoenv before invoking vim for editing the
`.enter` and `.exit` scripts, then enters the autoenv after vim exits.
This reduces the number of steps required to update the current autoenv
state.
2019-05-30 19:22:04 +01:00
0da54801e4 Fix HOME and END key bindings in zle 2019-05-22 10:51:54 +01:00
4b2b0d38c7 Drop fast-syntax-highlighting due to being wrong
When using `git` aliases, the alias would be highlighted red by
fast-syntax-highlighting even though the alias is valid so remove it and
go back to zsh-syntax-highlighting instead.
2019-05-02 12:10:37 +01:00
a095e9383c Escape * in vimdebug before passing to debug
With `setopt nonomatch` unescaped `*` can be used in command arguments
however when passing command arguments to `vimdebug` the `*` _should_
be escaped so that the debugger e.g. `gdb` will correctly invoke the
program where `setopt nonomatch` does not apply.
2019-04-18 10:41:12 +01:00
6bd2b8f0cc Add fzf to install 2019-03-24 16:24:31 +00:00
036f0255f8 Improve readability of posix exit codes in prompt 2019-03-13 11:12:37 +00:00
b842fb6437 Add utilities plugin with archive extract command 2019-01-21 12:47:09 +00:00
ce65ae40bc Add weather alias to curl wttr.in 2019-01-08 12:31:27 +00:00
1e46ca4633 Fix sandbox not using .enter 2018-11-30 19:45:25 +00:00
256cd06e5a build-dir now exports build_dir envvar
In addition to setting the `~build` hashed directory, also export the
`build_dir` environment variable to enable commands like this:

```
cmake . -B$build_dir
```
2018-11-07 10:58:04 +00:00
9037d2dd41 Default to using VIM's termdebug plugin for debug
VIM 8.1 added the optional plugin termdebug which integrates gdb
with separate buffers for source, output, and gdb console. This adds the
`vimdebug` command which enables the termdebug plugin and executes the
`:TermdebugCommand` with the given arguments.
2018-11-07 10:53:14 +00:00
7b87688885 Use pinentry-curses for lastpass-cli on Debian 2018-10-31 17:33:16 +00:00
352a1c3f12 Fix git-prompt not resetting bold for untracked 2018-10-15 11:48:23 +01:00
8b099b103b Add ~/Projects hashed directory 2018-09-13 10:28:51 +01:00
9eee926c56 Move variable decl into for loop in git-prompt.c 2018-09-12 09:53:07 +01:00
29fb84b995 Disable GCC warning for fread in git-prompt.c 2018-09-12 09:48:44 +01:00
5f2c5b58da Move entire git-prompt to C 2018-09-11 20:56:27 +01:00
2740f9bc8d Add paging to sandbox list command 2018-09-05 20:37:10 +01:00
2589b63023 Fix build-dir not stooping on error, remove build-dir.py 2018-09-03 11:32:58 +01:00
6a4531423e Make virtualenv and docker prompt vars local 2018-09-01 10:39:09 +01:00
8819cd4d18 Make C-S work in vim again 2018-08-30 22:48:26 +01:00
585925df38 Fix vi-mode grips
Tips from [zsh-vimto](https://github.com/laurenkt/zsh-vimto).

* Remove delay when changing mode
* Enable backspace when returning to viins from vicmd mode
2018-08-30 22:44:22 +01:00
2ac97afdd1 Update options
Fix spellings of various options, enable some new options found in
[https://github.com/willghatch/zsh-saneopt](zsh-saneopt).
2018-08-30 22:30:11 +01:00
f24253b8c1 Remove use of RPS1
Following on from the previous commit, use of `RPS1` results in the
prompt being redrawn when the terminal gets narrower, this makes the
line drawn by `fresh_line_one` scroll off the screen. By removing any
use of `RPS1` this behaviour goes away.
2018-08-30 21:57:18 +01:00
df819f58a8 Update fresh prompt
* When a command fails, don't print the error code at the end of the
  first line but directly after the git stats.
* Remove `cr` from `prompt_opts` since there is no longer a new line in
  `PS1`, combined with above, this result in no new lines being inserted
  when the terminal becomes narrower e.g. a horizontal tmux split.
* Remove `fresh_visible_length` function and instead use the length of
  string variables e.g. `${#userhost}`.
2018-08-30 21:04:05 +01:00
c636dd078c Update sandbox to use .enter and .exit 2018-08-28 22:15:33 +01:00
0992b65d17 Don't explicitly add python to PATH
After fixing the macOS `/etc/zprofile` issue rewriting the `PATH`
environment variable it is no longer necessary to explicitly add
`/usr/local/opt/python/libexec/bin` to `PATH` since Homebrew installed
python 2.x is installed in `/usr/local/bin` and is used by default.
2018-08-28 21:58:22 +01:00
9e9c43a0cf Fix error in build-dir when --build is not set 2018-08-28 14:44:19 +01:00
0ab04406ec Fix macOS PATH being rewritten in /etc/zprofile
macOS is obnoxious and overwrites the PATH from a users ~/.zshenv, which is
sourced first, in /etc/zprofile by calling `/usr/libexec/path_helper -s` so
this is required so that PATH is once again set to the desired value.
2018-08-26 20:19:12 +01:00
e17ff47d5e Only load layout when inside tmux 2018-08-26 19:11:29 +01:00
ff8bb3e4ab Change layout path to ~/.local/share/tmux/layouts 2018-08-26 18:39:02 +01:00
31d06e0f19 Add sandbox directory color to fresh_line_one 2018-08-26 15:37:30 +01:00
7bb6a459ee Fix autoenv's use of zstat 2018-08-25 15:45:11 +01:00
9e4c984822 Fix chsh to work on macOS 2018-08-24 18:26:13 +01:00
9af452a8e2 Update readme file 2018-08-24 12:29:15 +01:00
22 changed files with 1081 additions and 441 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,31 +0,0 @@
---
- location: ~/.config/zsh
- apt:
- zsh
- zsh-doc
- brew:
- zsh
- command:
- install: sudo chsh $USER -s `which zsh`
remove: sudo chsh $USER -s `which bash`
- 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/zdharma/fast-syntax-highlighting.git
- message: zsh will be the default prompt after next login

2
.gitignore vendored
View File

@@ -1,2 +1,2 @@
# Ignore all plugin files in subdirectories
*/*
*/

View File

@@ -2,15 +2,13 @@
<!-- 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
[conduit][conduit] as defined in the [`.conduit.yaml`](.conduit.yaml) file. This
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`.
```console
$ ansible-playbook main.yaml --ask-become-pass
```
## Prompt
@@ -51,10 +49,25 @@ display. This results in no noticeable lag when redrawing the prompt.
Plugins are sourced manually and their git repositories tracked by
[conduit][conduit], no plugin manager is used.
* [zsh-autosuggestions][zsh-autosuggestions] Fish-like autosuggestions for zsh.
* [zsh-syntax-highlighting][syntax] Fish shell like syntax highlighting for Zsh.
* [zsh-history-substring-search][search] Zsh port of the Fish shell's history
search.
In addition to third party plugins the following are custom plugins residing in
this repository.
* [autoenv](autoenv/autoenv.zsh) is a inspired by [zsh-autoenv][zsh-autoenv] but
simplified by removing customization points and using a less intrusive UI.
* [build](build/build.plugin.zsh) is a collection of commands to make it easier
to build projects focuses on C/C++ development.
* [sandbox](sandbox/sandbox.plugin.zsh) is a command which sets up a throw away
directory for quickly testing ideas.
* [layout](layout/layout.plugin.zsh) is a command which setups up `tmux` panes
in a window with scripts.
* [notes](notes/notes.plugin.zsh) is a command to quickly edit markdown note
files.
## Environment & Settings
The bulk of, if not all, configuration occurs in [`zshenv`](zshenv) and
@@ -135,6 +148,8 @@ Various aliases are defined at the end of [zshrc](zshrc) for convenience.
[zsh]: https://www.zsh.org/
[git]: https://git-scm.com/
[git-prompt]: https://github.com/olivierverdier/zsh-git-prompt
[zsh-autosuggestions]: https://github.com/zdharma/fast-syntax-highlighting
[zsh-autoenv]: https://github.com/Tarrasch/zsh-autoenv
[syntax]: https://github.com/zsh-users/zsh-syntax-highlighting
[search]: https://github.com/zsh-users/zsh-history-substring-search
[vim-mode]: https://github.com/sharat87/zsh-vim-mode

View File

@@ -16,6 +16,9 @@ _autoenv() {
init:'add .enter and .exit scripts in current directory'
edit:'edit .enter and .exit scripts in current directory'
deinit:'remove .enter and .exit scripts in current directory'
reload:'reload the current environment'
add=local:'add .local/bin to PATH'
add=py:'add Python virtualenv to the autoenv'
)
_describe -t commands command commands && ret=0 ;;
esac

View File

@@ -12,7 +12,7 @@ autoenv() {
case "$cmd" in
-h|--help) # Display help.
echo "\
usage: autoenv [-h] {init,edit,deinit}
usage: autoenv [-h] {init,edit,deinit,reload,add=py}
options:
-h, --help show this help message and exit
@@ -20,40 +20,60 @@ options:
commands:
init add .enter and .exit scripts in current directory
edit edit .enter and .exit scripts in current directory
deinit remove .enter and .exit scripts in current directory"
deinit remove .enter and .exit scripts in current directory
reload reload the current environment
add=local add .local/bin to PATH
add=py add Python virtualenv to the autoenv"
;;
init) # Create enter and exit scripts in current directory.
init) # Create .enter and .exit scripts in current directory.
if [ -f $PWD/.enter ] || [ -f $PWD/.exit ]; then
echo '.enter or .exit already exists'; return 1
fi
# Create then edit enter and exit scripts.
touch .enter .exit && autoenv edit
# Create the .enter and .exit scripts.
touch .enter .exit
# If enter script exists, authorize it.
[ -f $PWD/.enter ] && _autoenv_authorized $PWD/.enter yes
# If exit script exists, authorize it.
[ -f $PWD/.exit ] && _autoenv_authorized $PWD/.exit yes
# Enter the new autoenv.
_autoenv_enter $PWD ;;
# Edit the autoenv.
autoenv edit
# Enter the autoenv.
_autoenv_enter $PWD
;;
edit) # Edit enter and exit scripts in current directory.
edit) # Edit .enter and .exit scripts in current directory.
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
echo '.enter or .exit not found'; return 1
fi
# If vim exists, edit enter and exit scripts.
if which vim &> /dev/null; then
vim -p $PWD/.enter $PWD/.exit
# Exit the autoenv before editing.
_autoenv_exit $PWD
if $EDITOR -p $PWD/.enter $PWD/.exit; then
# If enter script exists, authorize it.
[ -f $PWD/.enter ] && _autoenv_authorized $PWD/.enter yes
# If exit script exists, authorize it.
[ -f $PWD/.exit ] && _autoenv_authorized $PWD/.exit yes
fi
# Enter the autoenv.
_autoenv_enter $PWD
else
echo 'vim not found'; return 1
fi ;;
fi
;;
deinit) # Remove enter and exit scripts in current directory.
if [ -f $PWD/.enter ] || [ -f $PWD/.exit ]; then
deinit) # Remove .enter and .exit scripts in current directory.
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
echo '.enter or .exit not found'; return 1
fi
# Prompt user to confirm removal of enter and exit scripts.
while true; do
read "answer?Are you sure [y/N]? "
case "$answer" in
y|Y|yes)
# Exit the autoenv.
_autoenv_exit $PWD
# Remove enter and exit scripts if they exist.
[ -f $PWD/.enter ] && rm $PWD/.enter
[ -f $PWD/.exit ] && rm $PWD/.exit
@@ -61,20 +81,67 @@ commands:
*) break ;;
esac
done
else
echo '.enter and .exit not found'; return 1
fi ;;
;;
reload) # Reload the current environment
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
echo '.enter or .exit not found'; return 1
fi
# Exit the autoenv before editing.
_autoenv_exit $PWD
# Enter the autoenv.
_autoenv_enter $PWD
;;
add=local) # Add .local/bin to PATH
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
echo '.enter or .exit not found'; return 1
fi
_autoenv_exit $PWD
# Create .local/bin if not present
if ! [ -d $PWD/.local/bin ]; then
mkdir -p $PWD/.local/bin
fi
# On enter: store PATH and insert .local/bin
echo 'OLDPATH=$PATH' >> .enter
echo 'PATH=$PWD/.local/bin:$PATH' >> .enter
# On exit: reset PATH
echo 'PATH=$OLDPATH' >> .exit
echo 'unset OLDPATH' >> .exit
# Authorize modified autoenv
_autoenv_authorized $PWD/.enter yes
_autoenv_authorized $PWD/.exit yes
_autoenv_enter $PWD
;;
add=py) # Add Python virtualenv to the sandbox
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
echo '.enter or .exit not found'; return 1
fi
_autoenv_exit $PWD
virtualenv -p `command -v python` .local
echo 'source ${0:a:h}/.local/bin/activate' >> .enter
echo 'deactivate' >> .exit
_autoenv_authorized $PWD/.enter yes
_autoenv_authorized $PWD/.exit yes
_autoenv_enter $PWD
pip install pynvim
;;
*) # Invalid arguments, show help then error.
echo "invalid arguments: $@"
autoenv --help
return 1 ;;
return 1
;;
esac
}
# Global entered directories array.
_autoenv_entered=()
# Load zstat from stat module for inspecting modified time.
zmodload -F zsh/stat b:zstat
# Check if the given file is authorized, if not prompt the user to authorize,
# ignore, or view the file. Authorized files and their modified times are
# stored in the ~/.cache/autoenv/authorized file to make authorization

View File

@@ -1,6 +1,7 @@
#compdef build-dir
_arguments \
'(-h --help)'{-h,--help}'[]' \
'(-h --help)'{-h,--help}'[show this help message and exit]' \
'(-s --show)'{-s,--show}'[show the current build directory]' \
'--build[invoke a build after selection]' \
'1:directory:_files'

View File

@@ -1,46 +0,0 @@
#!/usr/bin/env python
"""The pick_build_dir command selects a build directory
The pick_build_dir command scans the current directory for directories starting
with ``build`` and prompts the user to select one from the list.
"""
from __future__ import print_function
from argparse import ArgumentParser
from os import listdir
from os.path import curdir, isdir
from sys import stderr
from pick import Picker
def main():
"""Main entry point to build-dir.py script."""
parser = ArgumentParser()
parser.add_argument('output')
parser.add_argument('--default', action='store_true')
args = parser.parse_args()
directories = []
for directory in listdir(curdir):
if isdir(directory) and directory.startswith('build'):
directories.append(directory)
if len(directories) == 0:
print('no build directories found', file=stderr)
exit(1)
build_dirs = sorted(directories)
if args.default:
build_dir = build_dirs[0]
else:
picker = Picker(build_dirs, 'Select a build directory:')
picker.register_custom_handler(ord(''), lambda _: exit(1))
build_dir, _ = picker.start()
with open(args.output, 'w') as output:
output.write(build_dir)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
exit(130)

View File

@@ -7,7 +7,19 @@ alias build="build-dir --build"
# Detect installed debugger and set the `debug` alias to debug a program with
# command line arguments.
if [ `uname` = Linux ]; then
if which cgdb &> /dev/null; then
if [[ "`vim --version|head -1|cut -c 19-21`" =~ "^8\.[123456789]$" ]]; then
autoload -U regexp-replace
function vimdebug() {
# For each item in $* replace * and \* and then replace \ with \\
local args=()
for arg in "$@"; do
regexp-replace arg '\*' '\\*'
args+=($arg)
done
vim "+packadd termdebug" "+TermdebugCommand $args"
}
alias debug='vimdebug'
elif which cgdb &> /dev/null; then
alias debug='cgdb --args'
elif which gdb &> /dev/null; then
alias debug='gdb --args'
@@ -20,8 +32,8 @@ fi
# Interactively choose a `~build` directory for `build` to build.
build-dir() {
local usage='usage: build-dir [-h] [--build] [<directory>]'
local -a help do_build
zparseopts -D h=help -help=help -build=do_build
local -a help show do_build
zparseopts -D h=help -help=help s=show -show=show -build=do_build
if [[ -n $help ]]; then
cat << EOF
$usage
@@ -33,35 +45,48 @@ positional arguments:
optional arguments:
-h, --help show this help message and exit
-s, --show show the current build directory
--build invoke a build after selection
EOF
return
fi
error() { echo "\e[31merror:\e[0m $1"; return 1 }
local build_dir
error() { echo "\e[31merror:\e[0m $1" }
warning() { echo "\e[33mwarning:\e[0m $1" }
if [[ -n $show ]]; then
if [[ ! -n $build_dir ]]; then
error "build directory not set"
return 1
else
echo "$build_dir"
return
fi
fi
local local_build_dir
if [[ ${#*} -gt 1 ]]; then
echo $usage
error "unexpected position arguments: ${*[2,${#*}]}"
error "unexpected position arguments: ${*[2,${#*}]}"; return 1
elif [[ ${#*} -eq 1 ]]; then
build_dir=${*[1]}
[[ ! -d $build_dir ]] && \
error "directory not found: $build_dir"
if [[ ! -d ${*[1]} ]]; then
warning "directory not found: ${*[1]}"
else
local_build_dir=${*[1]}
fi
fi
# If <directory> was not set begin selection
if [[ -z $build_dir ]]; then
if [[ -z $local_build_dir ]]; then
# Find build directories
local -a build_dirs
local -a local_build_dirs
for entry in `ls -A`; do
[ -d $entry ] && [[ $entry =~ build* ]] && \
build_dirs+=${entry/\//}
local_build_dirs+=${entry/\//}
done
# Interactively select a build directory if more than 1 found
integer index=0
if [[ ${#build_dirs} -eq 0 ]]; then
error "no build directories found"
elif [[ ${#build_dirs} -gt 1 ]]; then
if [[ ${#local_build_dirs} -eq 0 ]]; then
error "no build directories found"; return 1
elif [[ ${#local_build_dirs} -gt 1 ]]; then
zmodload zsh/curses && {
# Get the size of the terminal
local size=`stty size`
@@ -86,13 +111,13 @@ EOF
zcurses string build-dir 'Select a build directory:'
# Add the selections text
for (( i = 0; i < ${#build_dirs}; i++ )); do
for (( i = 0; i < ${#local_build_dirs}; i++ )); do
integer line=$i+3
zcurses move build-dir $line 1
[[ $index -eq $i ]] &&
zcurses string build-dir "* " ||
zcurses string build-dir " "
zcurses string build-dir ${build_dirs[$i+1]}
zcurses string build-dir ${local_build_dirs[$i+1]}
done
# Display the text the and wait for input
@@ -104,7 +129,7 @@ EOF
(UP|k|$'\C-P')
[[ $index -gt 0 ]] && index=$index-1 ;;
(DOWN|j|$'\C-N')
[[ $index -lt ${#build_dirs}-1 ]] && index=$index+1 ;;
[[ $index -lt ${#local_build_dirs}-1 ]] && index=$index+1 ;;
(ENTER|$'\n')
break ;;
esac
@@ -121,46 +146,49 @@ EOF
# On success setup the build directory for use
if [[ $? -eq 0 ]]; then
# Set the build directory from selection if empty
[[ -z $build_dir ]] && \
build_dir=${build_dirs[$index+1]}
[[ -z $local_build_dir ]] && \
local_build_dir=${local_build_dirs[$index+1]}
# If `build.ninja` exists in alias `ninja`, return.
local build
[ -f $build_dir/build.ninja ] && \
build="ninja -C $build_dir"
[ -f $local_build_dir/build.ninja ] && \
build="ninja -C $local_build_dir"
# If `Makefile` exists in alias `make`, return.
if [ -f $build_dir/Makefile ]; then
if [ -f $local_build_dir/Makefile ]; then
[ `uname` = Darwin ] && \
local cpu_count=`sysctl -n hw.ncpu` ||
local cpu_count=`grep -c '^processor' /proc/cpuinfo`
build="make -j $cpu_count -C $build_dir"
build="make -j $cpu_count -C $local_build_dir"
fi
# If the build variable is not defined the command could not be determined
if [ -z $build ]; then
echo "\e[33mwarning:\e[0m build command detection failed: $build_dir"
warning "build command detection failed: $local_build_dir"
# Prompt user to enter a build command
vared -p 'enter comand: ' build
fi
# Redefine the `build` alias and update the `~build` hash directory
alias build="$build"
hash -d build=$build_dir
hash -d build=$local_build_dir
export build_dir=$local_build_dir
# If `--build` is specified then evaluate the command.
[[ -n $do_build ]] && eval build
if [[ -n $do_build ]]; then
eval build
fi
fi
}
# Build then run a target residing in `~build/bin`.
build-run() {
local target=$1; shift 1
eval build $target && ~build/bin/$target $*
eval build $target && ~build/bin/$target "$@"
}
# Build then debug a target residing in `~build/bin`.
build-debug() {
local target=$1; shift 1
eval build $target && debug ~build/bin/$target $*
eval build $target && debug ~build/bin/$target "$@"
}

105
cmake-uninstall Executable file
View File

@@ -0,0 +1,105 @@
#!/usr/bin/env python3
"""Uninstall a previously installed CMake installation.
Read the ``install_manifest.txt`` file from a CMake build directory
which has been installed then delete the files, and optionally the empty
subdirectories of the install prefix, specified within.
"""
from argparse import ArgumentParser, RawDescriptionHelpFormatter
from os import listdir, path, remove, rmdir
from sys import stderr
def uninstall(build_dir, recursive=False):
"""Uninstall a previoulsy installed CMake installation.
Arguments:
:build_dir: Path to the build directory containing the
``install_manifest.txt`` of files to uninstall.
:recursive: Boolean flag to enable recursively uninstall empty
directories up to the install prefix specified in ``CMakeCache.txt``.
"""
# Get the list of installed files from the install_manifest.txt
install_manifest_path = path.join(build_dir, 'install_manifest.txt')
with open(install_manifest_path, 'r') as install_manifest_file:
install_manifest = sorted(install_manifest_file.read().splitlines())
# Delete files from the filesystem
removed = []
directories = []
for entry in install_manifest:
directories.append(path.dirname(entry))
if path.isfile(entry):
remove(entry)
removed.append(entry)
if recursive:
# Get the install prefix from CMakeCache.txt
cmakecache_path = path.join(build_dir, 'CMakeCache.txt')
with open(cmakecache_path, 'r') as cmakecache_file:
for line in cmakecache_file.read().splitlines():
if line.startswith('CMAKE_INSTALL_PREFIX'):
prefix = path.normpath(line.split('=')[1])
break
while True:
# Remove duplicates from list
directories = list(dict.fromkeys(directories))
# Find directories in list which are not empty
not_empty = []
for index, entry in enumerate(directories):
if listdir(entry):
not_empty.append(index)
# Remove directories which are not empty from list
for index in reversed(not_empty):
del directories[index]
# Delete directories from the filesystem
to_del = []
to_append = []
for index, entry in enumerate(directories):
rmdir(entry)
removed.append(entry)
to_del.append(index)
parent = path.dirname(entry)
# Add parent directory to the list when not the install prefix
if path.normpath(parent) != prefix:
to_append.append(parent)
# Remove deleted directories from list
for index in reversed(to_del):
del directories[index]
directories += to_append
# Exit loop when no more directories in list
if not directories:
break
return removed
def main():
"""Command line entry point."""
cli = ArgumentParser(description=__doc__,
formatter_class=RawDescriptionHelpFormatter)
cli.add_argument('--version', action='version', version='%(prog)s 0.1.0')
cli.add_argument('-q',
'--quiet',
action='store_true',
help="don't print removed entries to stdout")
cli.add_argument('-r',
'--recursive',
action='store_true',
help='recursively remove empty directories')
cli.add_argument('build_dir',
help='path to the installed CMake build directory')
args = cli.parse_args()
try:
removed = uninstall(args.build_dir, recursive=args.recursive)
if not args.quiet:
for entry in removed:
print(f'-- Uninstalling: {entry}')
except FileNotFoundError as error:
print(f'error: file not found: {error.filename}', file=stderr)
exit(1)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
exit(130)

207
git-prompt.c Normal file
View File

@@ -0,0 +1,207 @@
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#if __linux__
#include <sys/wait.h>
#endif
#ifdef DEBUG
#define check(CONDITION) \
if (CONDITION) { \
fprintf(stderr, "error: %s: %d: %s\n", __FILE__, __LINE__, #CONDITION); \
exit(0); \
}
#else
#define check(CONDITION) \
if (CONDITION) { \
exit(0); \
}
#endif
#define color8(CODE) "\e[3" #CODE "m"
#define color256(CODE) "\e[38;5;" #CODE "m"
#define bold "\e[1m"
#define reset "\e[0m"
typedef struct process {
pid_t pid;
FILE* out;
} process_t;
process_t process_open(char* command) {
int fds[2];
check(pipe(fds));
int pid = fork();
check(pid == -1);
if (pid == 0) { // child process
close(fds[0]);
dup2(fds[1], STDOUT_FILENO);
dup2(STDOUT_FILENO, STDERR_FILENO);
char* argv[] = {"sh", "-c", command, NULL};
exit(execvp(argv[0], argv));
} else { // parent process
close(fds[1]);
process_t process = {pid, fdopen(fds[0], "rb")};
return process;
}
}
int process_close(process_t process) {
fclose(process.out);
int status;
check(process.pid != waitpid(process.pid, &status, 0));
if (WIFEXITED(status)) {
return WEXITSTATUS(status);
}
return 0;
}
char* trim(char* str) {
char* end;
while (isspace((unsigned char)*str)) str++;
if (*str == 0) {
return str;
}
end = str + strlen(str) - 1;
while (end > str && isspace((unsigned char)*end)) {
end--;
}
end[1] = '\0';
return str;
}
char* append(char* buffer, int count, ...) {
va_list list;
va_start(list, count);
for (int i = 0; i < count; i++) {
strcat(buffer, va_arg(list, char*));
}
va_end(list);
return buffer;
}
char* inttostr(char* buffer, int value) {
sprintf(buffer, "%d", value);
return buffer;
}
int main() {
// get the current branch name
process_t process = process_open("git symbolic-ref --short HEAD");
char branch_buf[256] = {};
fread(branch_buf, 1, sizeof(branch_buf), process.out);
if (process_close(process)) {
// current HEAD is not a symbolic ref
process = process_open("git rev-parse --abbrev-ref HEAD");
memset(branch_buf, 0, sizeof(branch_buf));
fread(branch_buf, 1, sizeof(branch_buf), process.out);
check(process_close(process));
if (strcmp("HEAD", trim(branch_buf)) == 0) {
// get the commit hash
process = process_open("git rev-parse --short HEAD");
memset(branch_buf, 0, sizeof(branch_buf));
fread(branch_buf, 1, sizeof(branch_buf), process.out);
check(process_close(process));
}
}
char* branch = trim(branch_buf);
char prompt[1024] = {};
append(prompt, 3, " " color256(66), branch, reset);
// get the upstream remote if one exists
char command[1024] = {};
append(command, 3, "git config branch.", branch, ".remote");
process = process_open(command);
char remote_buf[256] = {};
fread(remote_buf, 1, sizeof(remote_buf), process.out);
if (process_close(process) == 0) {
char* remote = trim(remote_buf);
// get the number of commits ahead of the remote
memset(command, 0, sizeof(command));
process = process_open(append(command, 5,
"git rev-list --right-only refs/remotes/",
remote, "/", branch, "...HEAD --count"));
char count[32] = {};
fread(count, 1, sizeof(count), process.out);
if(process_close(process) == 0 && strcmp("0", trim(count))) {
append(prompt, 2, "", trim(count));
}
// get the number of commits behind the remote
memset(command, 0, sizeof(command));
process = process_open(append(command, 5,
"git rev-list --left-only refs/remotes/",
remote, "/", branch, "...HEAD --count"));
memset(count, 0, sizeof(count));
fread(count, 1, sizeof(count), process.out);
if(process_close(process) == 0 && strcmp("0", trim(count))) {
append(prompt, 2, "", trim(count));
}
}
append(prompt, 1, " ");
// get the status and parse it
process = process_open("git status --porcelain");
char status[2048];
int indexed = 0, modified = 0, deleted = 0, untracked = 0, unmerged = 0;
while (NULL != fgets(status, sizeof(status) - 1, process.out)) {
char X = status[0];
char Y = status[1];
if (X == '?' && Y == '?') {
++untracked;
} else if ((X == 'A' && (Y == 'A' || Y == 'U')) ||
(X == 'D' && (Y == 'D' || Y == 'U')) ||
(X == 'U' && (Y == 'A' || Y == 'D' || Y == 'D' || Y == 'U'))) {
++unmerged;
} else {
switch (X) {
case ' ':
switch (Y) {
case 'M': ++modified; break;
case 'D': ++deleted; break;
} break;
case 'D': ++indexed;
switch (Y) {
case ' ': break;
case 'M': ++modified; break;
} break;
case 'M': case 'A': case 'R': case 'C': ++indexed;
switch (Y) {
case ' ': break;
case 'M': ++modified; break;
case 'D': ++deleted; break;
} break;
}
}
}
check(process_close(process));
if (indexed || modified || deleted || unmerged || untracked) { // modified
char int_buf[32];
if (indexed) {
append(prompt, 3, color8(2) "*", inttostr(int_buf, indexed), reset);
}
if (modified) {
append(prompt, 3, color8(1) "+", inttostr(int_buf, modified), reset);
}
if (deleted) {
append(prompt, 3, color8(1) "-", inttostr(int_buf, deleted), reset);
}
if (unmerged) {
append(prompt, 3, bold color8(1) "×", inttostr(int_buf, unmerged), reset);
}
if (untracked) {
append(prompt, 1, color8(1) "" reset);
}
} else { // clean
append(prompt, 1, bold color8(2) "" reset);
}
// print the prompt
puts(prompt);
return 0;
}

View File

@@ -1,7 +1,7 @@
#compdef layout
__get_layouts() {
ls -1 ~/.config/tmux/layouts 2>/dev/null | \
ls -1 ~/.local/share/tmux/layouts 2>/dev/null | \
while read -r layout; do echo $layout; done
}

View File

@@ -2,7 +2,7 @@ layout() {
if [[ "$1" == "" ]]; then
echo "usage: layout <layout> [name]"
else
tmux source-file ~/.config/tmux/layouts/$1
tmux source-file ~/.local/share/tmux/layouts/$1
if [[ "$2" != "" ]]; then
tmux rename-window $2
fi

View File

@@ -1,17 +1,18 @@
prompt_fresh_help() {
echo "\
options:
-a enable almostontop like behaviour"
-a enable almostontop like behaviour
-r recompile git-prompt executable"
}
prompt_fresh_setup() {
fresh_compile_git_prompt
# Parse options
local almostontop=0
while getopts 'a' opt; do
local recompile=0
while getopts 'ar' opt; do
case $opt in
a) local almostontop=1 ;;
r) local recompile=1 ;;
*) prompt -h fresh; return 1 ;;
esac
done
@@ -19,40 +20,43 @@ prompt_fresh_setup() {
autoload -U add-zsh-hook
# Hook to print the first line of the "two line" prompt, this line is not
# actually part of the prompt so does not get redrawn which can sometimes
# cause lines before the prompt to disappear.
# actually part of the prompt so does not get redrawn, this is preferable
# since sometimes lines before the prompt can disappear.
add-zsh-hook precmd fresh_line_one
if [ $almostontop -eq 1 ]; then
# Hook to clear the screen then prints the prompt with previous command at
# 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
add-zsh-hook -d preexec fresh_almostontop
add-zsh-hook -d preexec fresh_almostontop_preexec
add-zsh-hook -d precmd fresh_almostontop_precmd
fi
if [ "$USERNAME" = "root" ]; then
local user="%{%F{9}%}%n%{%f%}"
[ $recompile -eq 1 ] && prompt_cleanup
fresh_compile_git_prompt
if [ "$USER" = "root" ]; then
local user="%{%F{1}%}%n%{%f%}"
else
local user="%{%F{35}%}%n%{%f%}"
fi
if [ "$SSH_CONNECTION" != "" ]; then
local user="%{%F{35}%}$user%{%f%}@%{%F{244}%}%M%{%f%}"
local userhost=$USER
if [ "$SSH_CONNECTION" != "" ] || [ "$DISTROBOX_ENTER_PATH" != "" ]; then
local user="$user@%{%F{244}%}%M%{%f%}"
local userhost="$userhost@`hostname`"
fi
local length=`fresh_visible_length "$user"`
PS1="«$user» "
PS2="${(l:$length + 1:: :)}» "
PS2="«${(l:${#userhost}:: :)}» "
RPS1='$(fresh_rprompt)'
prompt_opts=(cr percent sp subst)
prompt_opts=(percent sp subst)
}
prompt_cleanup() {
if [ -f ~/.cache/zsh/git-prompt ]; then rm ~/.cache/zsh/git-prompt; fi
[ -f ~/.cache/zsh/git-prompt ] && rm ~/.cache/zsh/git-prompt
}
fresh_line_one() {
@@ -61,157 +65,119 @@ fresh_line_one() {
# Construct the time and directory portions of the prompt
local time_stamp="%{%F{244}%}%D{%H:%M:%S}%{%f%}"
[[ -n $SANDBOX_HOME ]] && \
local directory="%{%F{220}%}$SANDBOX_NAME${PWD#$SANDBOX_HOME}%{%f%}" || \
local directory="%{%F{37}%}%~%{%f%}"
# Check we are in a git repository
if `git rev-parse --git-dir > /dev/null 2>&1`; then
# Get git branch name & exit early if not found
local branch="`git symbolic-ref HEAD 2> /dev/null`"
if [ "" = "$branch" ]; then
local branch="`git rev-parse --abbrev-ref HEAD`"
if [ "HEAD" = "$branch" ]; then
local branch="`git rev-parse --short $branch`"
fi
local git=`~/.cache/zsh/git-prompt`
# If the last command failed, display its error code at the right
if [[ $exit_code -ne 0 ]]; then
case $exit_code in
129) exit_code="SIGHUP" ;; # 128 + 1
130) exit_code="SIGINT" ;; # 128 + 2
131) exit_code="SIGQUIT" ;; # 128 + 3
132) exit_code="SIGILL" ;; # 128 + 4
133) exit_code="SIGTRAP" ;; # 128 + 5
134) exit_code="SIGABRT" ;; # 128 + 6
134) exit_code="SIGIOT" ;; # 128 + 6
135) exit_code="SIGBUS" ;; # 128 + 7
136) exit_code="SIGFPE" ;; # 128 + 8
137) exit_code="SIGKILL" ;; # 128 + 9
138) exit_code="SIGUSR1" ;; # 128 + 10
139) exit_code="SIGSEGV" ;; # 128 + 11
140) exit_code="SIGUSR2" ;; # 128 + 12
141) exit_code="SIGPIPE" ;; # 128 + 13
142) exit_code="SIGALRM" ;; # 128 + 14
143) exit_code="SIGTERM" ;; # 128 + 15
144) exit_code="SIGSTKFLT" ;; # 128 + 16
145) exit_code="SIGCHLD" ;; # 128 + 17
146) exit_code="SIGCONT" ;; # 128 + 18
147) exit_code="SIGSTOP" ;; # 128 + 19
148) exit_code="SIGTSTP" ;; # 128 + 20
149) exit_code="SIGTTIN" ;; # 128 + 21
150) exit_code="SIGTTOU" ;; # 128 + 22
151) exit_code="SIGURG" ;; # 128 + 23
152) exit_code="SIGXCPU" ;; # 128 + 24
153) exit_code="SIGXFSZ" ;; # 128 + 25
154) exit_code="SIGVTALRM" ;; # 128 + 26
155) exit_code="SIGPROF" ;; # 128 + 27
156) exit_code="SIGWINCH" ;; # 128 + 28
157) exit_code="SIGIO" ;; # 128 + 29
158) exit_code="SIGPWR" ;; # 128 + 30
159) exit_code="SIGSYS" ;; # 128 + 31
esac
local result=" %{%B%F{1}%}$exit_code%{%f%b%}"
fi
if [ "$branch" != "" ]; then
local branch=${branch#refs/heads/}
# Get the number of commits ahead/behind from the remote branch
local remote="`git config branch.$branch.remote 2> /dev/null`"
if [ "" != "remote" ]; then
local branches="refs/remotes/$remote/$branch...HEAD"
local nahead=`git rev-list --right-only $branches --count 2> /dev/null`
if [ "0" -ne "$nahead" ]; then local ahead="↑$nahead"; fi
local nbehind=`git rev-list --left-only $branches --count 2> /dev/null`
if [ "0" -ne "$nbehind" ]; then local behind="↓$nbehind"; fi
# Unset vim/tmux navigate flag to handle C-z and multiple vim jobs.
[[ ! -z "$TMUX" ]] && \
[[ "`tmux show-window-options`" = *"@vim$TMUX_PANE"* ]] && \
tmux set-window-option -u @vim$TMUX_PANE
# If a virtualenv is enabled, display it's basename
if [[ ! -z "$VIRTUAL_ENV" ]]; then
local py=" %{%F{4}%}py%{%f%}%{%F{3}%}$(basename $VIRTUAL_ENV)%{%f%}"
fi
# Construct the git prompt
local git="%{%F{66}%}$branch%{%f%}$ahead$behind "
if [ -f ~/.cache/zsh/git-prompt ]; then
# Get the change counts from git-prompt
local counts=(`~/.cache/zsh/git-prompt`)
# Parse the results from git-prompt
if [ 0 -eq ${#counts[@]} ]; then # clean
local git="$git%{%B%F{2}%}✓%{%f%b%}";
else
if [ 0 != $counts[1] ]; then # indexed
local git="$git%{%F{2}%}*$counts[1]%{%f%}"
# If docker-machine env is active, display the machines name
if [[ ! -z "$DOCKER_MACHINE_NAME" ]]; then
local docker=" %{%F{6}%}$DOCKER_MACHINE_NAME%{%f%}"
fi
if [ 0 != $counts[2] ]; then # modified
local git="$git%{%F{1}%}+$counts[2]%{%f%}";
fi
if [ 0 != $counts[3] ]; then # deleted
local git="$git%{%F{1}%}-$counts[3]%{%f%}";
fi
if [ 0 != $counts[4] ]; then # unmerged
local git="$git%{%B%F{1}%}×$counts[4]%{%f%b%}";
fi
if [ 0 != $counts[5] ]; then # untracked
local git="$git%{%F{1}%}…%{%f%}";
fi
fi
fi
fi
fi
# Construct the prompt string
local line="$time_stamp $directory $git"
# Print the first line of the prompt
if [[ $exit_code -eq 0 ]]; then
print -P "$line"
else
# The last command failed, display its error code at the right
local result="%{%B%F{1}%}$exit_code%{%f%b%}"
local length=`fresh_visible_length "$line$result"`
print -P "$line${(l:COLUMNS - $length - 1:: :)}$result"
fi
print -P "$time_stamp $directory$git$py$docker$result"
}
fresh_rprompt() {
rprompt=""
if [[ ! -z "$DOCKER_MACHINE_NAME" ]]; then
rprompt="$rprompt %{%F{3}%}$DOCKER_MACHINE_NAME%{%f%}"
fi
if [[ ! -z "$VIRTUAL_ENV" ]]; then
rprompt="$rprompt %{%F{3}%}$(basename $VIRTUAL_ENV)%{%f%}"
fi
echo $rprompt
# Executed before each prompt.
fresh_almostontop_precmd() {
# 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_before
read -s -d \; row_before
# Discard suffix delimted by R otherwise it is output to the tty
read -s -d R
}
fresh_almostontop() {
clear
fresh_line_one
print -P "$PROMPT"'$1'
}
fresh_visible_length() {
echo $(( ${#${(S%%)1//(\%(KF1]|)\{*\}|\%[Bbkf])}} ))
# 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() {
# Compile a simple C executable which parses the output of `git status
# --procelain` to greatly decrease the time taken to render the prompt
local cache=~/.cache/zsh
if [ ! -d $cache ]; then mkdir -p $cache; fi
if [ ! -f $cache/git-prompt ]; then
cc -x c -std=gnu99 -O3 -DNDEBUG -o $cache/git-prompt - 2> /dev/null << EOF
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *file = popen("git status --porcelain", "r");
if (NULL == file) { return 0; }
char status[2048];
int indexed = 0, modified = 0, deleted = 0, untracked = 0, unmerged = 0;
while (NULL != fgets(status, sizeof(status) - 1, file)) {
char X = status[0];
char Y = status[1];
if (X == '?' && Y == '?') {
++untracked;
} else if ((X == 'A' && (Y == 'A' || Y == 'U')) ||
(X == 'D' && (Y == 'D' || Y == 'U')) ||
(X == 'U' && (Y == 'A' || Y == 'D' || Y == 'D' || Y == 'U'))) {
++unmerged;
} else {
switch (X) {
case ' ':
switch (Y) {
case 'M': ++modified; break;
case 'D': ++deleted; break;
} break;
case 'D': ++indexed;
switch (Y) {
case ' ': break;
case 'M': ++modified; break;
} break;
case 'M': case 'A': case 'R': case 'C': ++indexed;
switch (Y) {
case ' ': break;
case 'M': ++modified; break;
case 'D': ++deleted; break;
} break;
}
}
}
pclose(file);
if (indexed || modified || deleted || unmerged || untracked) {
printf("%d %d %d %d %d", indexed, modified, deleted, unmerged, untracked);
}
return 0;
}
EOF
# Compile a simple C program which parses the output of `git status
# --procelain` to greatly decrease the time taken to draw the prompt
[ ! -d ~/.cache/zsh ] && mkdir -p ~/.cache/zsh
if [ ! -f ~/.cache/zsh/git-prompt ]; then
cc -std=gnu99 -O3 -DNDEBUG -Wno-unused-result \
~/.config/zsh/git-prompt.c -o ~/.cache/zsh/git-prompt
if [ $? -ne 0 ]; then
echo "git prompt disabled, are the system development headers installed?"
echo "git-prompt was not compiled, is a C99 toolchain installed?"
fi
fi
}

View File

@@ -1,16 +1,21 @@
#compdef sandbox
__get_sandboxes() {
/bin/ls $SANDBOX_ROOT 2> /dev/null
}
__sandboxes() {
local -a sandboxes
sandboxes=(${(fo)"$(__get_sandboxes)"})
sandboxes=(${(fo)"$(ls $SANDBOX_ROOT 2> /dev/null)"})
_describe 'in' sandboxes
}
_sandbox_cmds() {
_sandbox() {
local context curcontext="$curcontext" state line
typeset -A opt_args
_arguments -C \
'1: :->cmd' \
'*:: :->args'
case $state in
(cmd)
local commands; commands=(
'create:Create a new sandbox'
'rename:Rename an existing sandbox'
@@ -20,27 +25,18 @@ _sandbox_cmds() {
'disable:Disable the current sandbox'
)
_describe -t commands 'sandbox command' commands "$@"
}
;;
_sandbox() {
local context curcontext="$curcontext" state line
typeset -A opt_args
_arguments -C \
'1: :_sandbox_cmds' \
'*::arg:->args'
case $state in
(args)
curcontext="${curcontext%:*:*}:sandbox-cmd-$words[1]:"
case $line[1] in
(create|list|disable)
(create)
_arguments -C '--git[repository to clone]: :'
;;
(enable|destroy)
(rename|enable|destroy)
_arguments -C '1:: :__sandboxes'
;;
(rename)
_arguments -C '1:: :__sandboxes'
(list|disable)
;;
esac
esac

View File

@@ -1,103 +1,133 @@
if [[ "" == $SANDBOX_ENV_IN_FILE ]]; then
export SANDBOX_ENV_IN_FILE=$AUTOENV_IN_FILE
fi
if [[ "" == $SANDBOX_ENV_OUT_FILE ]]; then
export SANDBOX_ENV_OUT_FILE=$AUTOENV_OUT_FILE
fi
if [[ "" == $SANDBOX_ROOT ]]; then
export SANDBOX_ROOT=$HOME/Sandbox
fi
sandbox() {
local usage="usage: sandbox {create,destroy,enable,disable} [name]"
local usage="\
usage: sandbox [-h] {create,rename,destroy,enable,disable,list} ..
sandbox create [--git <repo>] <name>
sandbox rename <old-name> <new-name>
sandbox destroy <name>
sandbox enable <name>
sandbox disable
sandbox list"
if [[ "" == $1 ]]; then
echo $usage
return 1
fi
error() { print -P "%F{red}error:%f $1" }
case $1 in
local cmd=$1
[[ -z "$cmd" ]] && \
error "missing command\n$usage" && return 1
shift 1
case $cmd in
create)
if [[ "" == $2 ]]; then
echo $usage
return 1
# Parse command arguments.
local git=false
for arg in $@; do
if [ "${arg[1]}" = - ]; then
if [ "$git" = true ]; then
error "invalid --git <repo> $arg\n$usage" && return 1
elif [ "$arg" = --git ]; then
git=true
else
error "invalid option $arg\n$usage" && return 1
fi
local sandbox=$SANDBOX_ROOT/$2
if [[ -d $sandbox ]]; then
echo "Sandbox '$2' already exists"
return 2
else
if [ "$git" = true ]; then
local repo=$arg
git=false
elif [[ -n "$name" ]]; then
error "invalid argument $arg\n$usage" && return 1
else
local name=$arg
fi
fi
done
unset git
[[ -z "$name" ]] && \
error "missing argument <name>\n$usage" && return 1
local sandbox=$SANDBOX_ROOT/$name
[[ -d "$sandbox" ]] && \
error "sandbox already exists $name" && return 1
if [[ -n "$repo" ]]; then
mkdir -p $SANDBOX_ROOT &> /dev/null
git clone $repo $sandbox
cd $sandbox
else
mkdir -p $sandbox &> /dev/null
begin=$PWD
cd $sandbox
echo "SANDBOX_HOME=\$(dirname -- "\$0:a")" >> $SANDBOX_ENV_IN_FILE
echo "SANDBOX_NAME=$2" >> $SANDBOX_ENV_IN_FILE
echo "unset SANDBOX_NAME" >> $SANDBOX_ENV_OUT_FILE
echo "unset SANDBOX_HOME" >> $SANDBOX_ENV_OUT_FILE
git init &> /dev/null
fi
cd $begin
cd $sandbox
echo "SANDBOX_HOME=\$(dirname -- "\$0:a")" >> $sandbox/.enter
echo "SANDBOX_NAME=$name" >> $sandbox/.enter
_autoenv_authorized $sandbox/.enter yes
echo "unset SANDBOX_NAME" >> $sandbox/.exit
echo "unset SANDBOX_HOME" >> $sandbox/.exit
_autoenv_authorized $sandbox/.exit yes
_autoenv_enter $sandbox
;;
rename)
if [[ "" == $2 || "" == $3 ]]; then
echo $usage
return 1
fi
local old_name=$1 new_name=$2
[[ -z "$old_name" ]] && \
error "missing argument <old-name>\n$usage" && return 1
[[ -z "$new_name" ]] && \
error "missing argument <new-name>\n$usage" && return 1
mv $SANDBOX_ROOT/$2 $SANDBOX_ROOT/$3
sed -i "" "s/$2/$3/g" $SANDBOX_ROOT/$3/.env
local old=$SANDBOX_ROOT/$old_name new=$SANDBOX_ROOT/$new_name
[[ ! -d "$old" ]] && \
error "sandbox does not exist $old_name" && return 1
[[ -d "$new" ]] && \
error "sandbox already exists $new_name" && return 1
[[ "$PWD" = "$old"* ]] && _autoenv_exit $PWD
mv $old $new
sed -i "s/$old_name/$new_name/g" $new/.enter
_autoenv_authorized $new/.enter yes
_autoenv_authorized $new/.exit yes
[[ "$PWD" = "$old"* ]] && cd $new
;;
destroy)
if [[ "" == $2 ]]; then
echo $usage
return 1
fi
local name=$1
[[ -z "$name" ]] && \
error "missing argument <name>\n$usage" && return 1
local sandbox=$SANDBOX_ROOT/$2
if [[ ! -d $sandbox ]]; then
echo "Sandbox '$2' does not exist"
return 2
fi
local sandbox=$SANDBOX_ROOT/$name
[[ ! -d $sandbox ]] && \
error "sandbox does not exist $name" && return 1
cd -
if [[ "${SANDBOX_ROOT##$PWD}" = "${SANDBOX_ROOT}" ]]; then
cd $HOME
fi
[[ "$PWD" = "$sandbox"* ]] && cd ~
rm -rf $sandbox
;;
list)
/bin/ls -1 $SANDBOX_ROOT
ls -1 $SANDBOX_ROOT | less -F -K -R -X
;;
enable)
if [[ "" == $2 ]]; then
echo $usage
return 1
fi
local name=$1
[[ -z "$name" ]] && \
error "missing argument <name>\n$usage" && return 1
local sandbox=$SANDBOX_ROOT/$2
if [[ ! -d $sandbox ]]; then
echo "Sandbox '$2' does not exist"
return 2
fi
local sandbox=$SANDBOX_ROOT/$name
[[ ! -d $sandbox ]] && \
error "sandbox does not exist $name" && return 1
export SANDBOX_RETURN=$PWD
cd $sandbox
;;
disable)
if [[ -z $SANDBOX_RETURN ]]; then
echo "Sandbox is not currently active"
return 2
fi
[[ -z "$SANDBOX_RETURN" ]] && \
error "sandbox is not currently active" && return 1
cd $SANDBOX_RETURN
unset $SANDBOX_RETURN
unset SANDBOX_RETURN
;;
esac
}

99
tasks.yaml Normal file
View File

@@ -0,0 +1,99 @@
---
- 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:
- pinentry-curses
- silversearcher-ag
- unzip
- zsh-doc
state: present
- name: zsh install macOS packages
when: ansible_os_family == "Darwin"
become: false
homebrew:
name: the_silver_searcher
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

19
update-completion-links.zsh Executable file
View File

@@ -0,0 +1,19 @@
#!/usr/bin/env zsh
# Check if third party completions are present.
local zsh_completions=~/.config/zsh/zsh-completions
[ ! -d $zsh_completions ] && return 0
# Loop over all completions.
for completion in $zsh_completions/src/_*; do
local name=`basename $completion`
local symlink=~/.local/share/zsh/site-functions/$name
# Remove existing completion file if it exists.
[ -f $symlink ] && rm $symlink
# Check if the command exists on the PATH.
if command -v ${name:1} &> /dev/null; then
# Symlink the completion for the existing command.
[ `uname` = Darwin ] && \
ln -s $completion $symlink || ln -sr $completion $symlink
fi
done

View File

@@ -0,0 +1,104 @@
# A collection of various shell utilities.
autoload colors && colors
# Abstract different ways to copy to the clipboard.
if [ -n "$SSH_CONNECTION" ] ; then
# Use OSC-52 to set the clipboard
alias copy='base64 | xargs -0 printf "\033]52;c;%s\a"'
elif [ "`uname`" = "Darwin" ]; then
# Use pbcopy to set the clipboard
alias copy='pbcopy'
elif which xclip &> /dev/null; then
# Use xclip to set the clipboard
alias copy='xclip -selection c'
fi
# Abstract different ways to paste from the clipboard.
# TODO: Use OSC-52 to get the clipboard, not widely supported though
if [ "`uname`" = "Darwin" ]; then
# Use pbpaste to get the clipboard
alias paste='pbpaste'
elif which xclip &> /dev/null; then
# Use xclip to get the clipboard
alias paste='xclip -selection c -o'
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.
extract() {
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.tar.xz) [ `"uname"` = "Darwin" ] && tar xvJf $1 || tar xf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7zr x $1 ;;
*) echo "$fg[red]error:$reset_color unable to extract '$1'" ;;
esac
else
echo "$fg[red]error:$reset_color file not found '$1'"
fi
}
if which bat &> /dev/null; then
# Wrap bat to specify a theme, always enable color, pipe the output to less.
# Both --theme and --color can be specified multiple times and will override
# these defaults.
bat() {
command bat --theme='TwoDark' --color always --paging auto "$@"
}
elif which batcat &> /dev/null; then
bat() {
command batcat --theme='TwoDark' --color always --paging auto "$@"
}
fi
if which docker-machine &> /dev/null; then
# Wrap the docker command to print a message if a docker-machine is not
# running, rather than just stating it can not find it's socket.
docker() {
command docker "$@"
if ! docker-machine active &> /dev/null; then
echo "$fg[red]error:$reset_color no active host found, run:" \
"docker-machine start <machine>"
return 1
fi
}
# Wrap the docker-machine command to automatically update the environment.
# When a machine is started, set the environment variables provided by
# docker-machine env <machine>. When a machine is stopped, unset the same
# variables.
docker-machine() {
command docker-machine "$@"
if [ "start" = "$1" ]; then
eval `docker-machine env $2`
elif [ "stop" = "$1" ]; then
unset DOCKER_MACHINE_NAME
unset DOCKER_CERT_PATH
unset DOCKER_HOST
unset DOCKER_TLS_VERIFY
fi
}
fi

View File

@@ -1,2 +1,7 @@
# .zprofile [1] Used for executing user's commands at start, will be sourced
# when starting as a login shell.
# macOS is obnoxious and overwrites the PATH from a users ~/.zshenv, which is
# sourced first, in /etc/zprofile by calling `/usr/libexec/path_helper -s` so
# this is required so that PATH is once again set to the desired value.
[ `uname` = Darwin ] && source ~/.zshenv

77
zshenv
View File

@@ -5,22 +5,55 @@
# Enable saving command history to file
[ ! -d $HOME/.cache/zsh ] && mkdir -p $HOME/.cache/zsh
HISTFILE=$HOME/.cache/zsh/histfile
HISTSIZE=5000
SAVEHIST=5000
HISTSIZE=20000
SAVEHIST=20000
# Remove vi mode switch delay
KEYTIMEOUT=1
# Enable time stats for long lasting commands
REPORTTIME=5
# Add Homebrew python to PATH on macOS if present
[ "`uname`" = "Darwin" ] && [ -d /usr/local/opt/python/libexec/bin ] &&
PATH=/usr/local/opt/python/libexec/bin:$PATH
# Add ~/.local to the environment
fpath+=$HOME/.local/share/zsh/site-functions
PATH=$HOME/.local/bin:$PATH
MANPATH=$HOME/.local/share/man:$MANPATH
INFOPATH=$HOME/.local/share/info:$INFOPATH
# Add ccache compiler aliases to PATH and use XDG base dir paths
if [ `uname` = Darwin ]; then
[ -d /usr/local/opt/python/libexec/bin ] && \
PATH=/usr/local/opt/python/libexec/bin:$PATH
[ -f /usr/local/bin/ccache ] && \
PATH=/usr/local/opt/ccache/libexec:$PATH
elif [ -f /usr/bin/ccache ]; then
if [ -d /usr/lib/ccache/bin ]; then
PATH=/usr/lib/ccache/bin:$PATH
elif [ -d /usr/lib/ccache ]; then
PATH=/usr/lib/ccache:$PATH
fi
fi
export CCACHE_CONFIGPATH=$HOME/.config/ccache
export CCACHE_DIR=$HOME/.cache/ccache
# Add default CMake generator
command -v ninja &> /dev/null && \
export CMAKE_GENERATOR=Ninja
# Remove duplicates from environment variables
typeset -U fpath
typeset -U PATH; export PATH
typeset -U MANPATH; export MANPATH
typeset -U INFOPATH; export INFOPATH
# Set default editor.
if command -v nvim &> /dev/null; then
export EDITOR=`command -v nvim`
elif command -v vim &> /dev/null; then
export EDITOR=`command -v vim`
fi
export GIT_EDITOR=$EDITOR
# Use ~/.local for pip installs on macOS
[ "`uname`" = "Darwin" ] && export PYTHONUSERBASE=$HOME/.local
@@ -32,11 +65,41 @@ export LESS_TERMCAP_so=`printf "\e[1;40;32m"`
export LESS_TERMCAP_se=`printf "\e[0m"`
export LESS_TERMCAP_us=`printf "\e[0;34m"`
export LESS_TERMCAP_ue=`printf "\e[0m"`
# Disable storing less history
export LESSHISTFILE=/dev/null
# Force GoogleTest to output colors
export GTEST_COLOR=yes
# Allow completions for GoogleTest break on failure
export GTEST_BREAK_ON_FAILURE=0
# Force CTest to verbose output
export CTEST_OUTPUT_ON_FAILURE=1
# User ~/.local/share for persistent pylint data
export PYLINTHOME=~/.local/share/pylint
# Disable virtualenv prompt
VIRTUAL_ENV_DISABLE_PROMPT=1
export VIRTUAL_ENV_DISABLE_PROMPT=1
# If pinentry-curses exists, use it for lastpass-cli
command -v pinentry-curses &> /dev/null && \
export LPASS_PINENTRY=pinentry-curses
# Teach these some XDG Base Directory Spec manners
export IPYTHONDIR=$HOME/.config/ipython
command -v cargo &> /dev/null && \
export CARGO_HOME=$HOME/.local/share/cargo
if command -v ccache &> /dev/null; then
export CCACHE_CONFIGPATH=$HOME/.config/ccache.conf
export CCACHE_DIR=$HOME/.cache/ccache
fi
command -v conan &> /dev/null && \
export CONAN_USER_HOME=$HOME/.local/share/conan
command -v docker &> /dev/null && \
export DOCKER_CONFIG=$HOME/.local/share/docker
export GTK_RC_FILES=$HOME/.config/gtk/gtkrc
export GTK2_RC_FILES=$HOME/.config/gtk-2.0/gtkrc
export PYLINTHOME=$HOME/.cache/pylint
command -v rustup &> /dev/null && \
export RUSTUP_HOME=$HOME/.local/share/rustup
export WGETRC=$HOME/.config/wget/rc
# TODO: terminfo

91
zshrc
View File

@@ -17,13 +17,11 @@ ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(end-of-line vi-end-of-line)
# Search history with a command substring
source-plugin zsh-history-substring-search
HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND=
HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND=
# Command syntax highlighting
source-plugin fast-syntax-highlighting
fast-theme -q ~/.config/zsh/fresh.ini
# Automatically source .enter and .exit scripts on cd
source-plugin autoenv
source-plugin zsh-syntax-highlighting
# Build system helper commands
source-plugin build
@@ -31,19 +29,26 @@ source-plugin build
# Project sandboxing commands
source-plugin sandbox
# Various shell utilities
source-plugin utilities
# Automatically source .enter and .exit scripts on cd
source-plugin autoenv
# Layout tmux window commands
source-plugin layout
[ "$TMUX" != "" ] && source-plugin layout
# Note taking commands
source-plugin notes
# Remove duplicates from history
setopt hist_ignore_all_dups
setopt hist_reduce_blanks
setopt hist_save_no_dups
setopt histignoredups
# Enable multi-terminal history
setopt inc_append_history
setopt share_history
# Disable error when no glob matches are found
setopt nonomatch
# Enable comments in the prompt
setopt interactive_comments
@@ -52,17 +57,20 @@ setopt interactive_comments
setopt ignore_eof
# Disable sound
unsetopt beep
setopt nobeep
# Disable tty flow control, allows vim to use '<Ctrl>S'
unsetopt flow_control && stty -ixon
setopt noflowcontrol; stty -ixon
# Enable completions in the middle of a word
setopt completeinword
# Initialize completions
autoload -U compinit
compinit
compinit -d ~/.cache/zsh/compdump
# Add pip to the old completion engine if present
if which pip &> /dev/null; then
if command -v pip &> /dev/null; then
function _pip_completion {
local words cword
read -Ac words
@@ -82,6 +90,9 @@ prompt fresh
# Enable vi mode line editor keymap
bindkey -v
# Enable backspace after returning to viins from vicmd mode
bindkey '^?' backward-delete-char
# Enable yank, change, and delete whole line with 'Y', 'cc', and 'dd'
bindkey -M vicmd 'Y' vi-yank-whole-line
@@ -120,17 +131,22 @@ autoload -U edit-command-line
zle -N edit-command-line
bindkey -M vicmd '^V' edit-command-line
# Get the shells parent process name.
ppid_name() { echo $(ps -p $(ps -p $(echo $$) -o ppid=) -o comm=) }
# Enable HOME and END keys
if [[ `uname` = Linux ]]; then
# If Home and End are not working as expected setup zkbd mappings.
[ -f ~/.zkbd/$TERM-${${DISPLAY:t}:-$VENDOR-$OSTYPE} ] && \
source ~/.zkbd/$TERM-${${DISPLAY:t}:-$VENDOR-$OSTYPE}
[[ -n ${key[Home]} ]] && bindkey "${key[Home]}" beginning-of-line
[[ -n ${key[End]} ]] && bindkey "${key[End]}" end-of-line
fi
# Enable changing cursor shape based on vi mode
if [ "$ITERM_PROFILE" != "" ] && [ "$TMUX" = "" ]; then
# iTerm2 cursor shape escape sequences outside tmux
cursor_block="\e]50;CursorShape=0\C-G"
cursor_line="\e]50;CursorShape=1\C-G"
elif [ "$(ppid_name)" != "python2" ]; then
# iTerm2 inside tmux or VTE compatible cursor shape escape sequences,
# exclude Guake even though it's VTE based it doesn't like these
else
# iTerm2 inside tmux or VTE compatible cursor shape escape sequences.
cursor_block="\e[2 q"
cursor_line="\e[6 q"
fi
@@ -155,48 +171,35 @@ if [[ ! -z "$cursor_block" && ! -z "$cursor_line" ]]; then
zle -N zle-line-finish
fi
# Frequntly used directories
function frequent-directory() { export $1; hash -d $1 }
frequent-directory Projects="$HOME/Projects"
frequent-directory Sandbox="$HOME/Sandbox"
# Load work related config
[ -f ~/.config/work/zshrc ] && source ~/.config/work/zshrc
# Remove duplicates from environment variables
typeset -U PATH
typeset -U MANPATH
typeset -U INFOPATH
# Add ccache symlink directory to start of PATH, this must be after
# `typeset -U PATH` because on macOS this reorders the list so ccache's
# symlinks will no longer be at the start of PATH rendering it unusable.
if [ `uname` = Darwin ]; then
[ -f /usr/local/bin/ccache ] && \
PATH=/usr/local/opt/ccache/libexec:$PATH
else
[ -f /usr/bin/ccache ] && \
PATH=/usr/lib/ccache:$PATH
fi
# Aliases
alias grep='grep --color=always'
which cmake &> /dev/null && \
command -v cmake &> /dev/null && \
alias cninja='cmake -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON'
which ssh &> /dev/null && \
command -v ssh &> /dev/null && \
alias ssh='TERM=xterm-256color ssh'
alias weather="curl wttr.in"
alias cls="clear && printf '\e[3J'"
case `uname` in
Linux)
[ "$TMUX" = "" ] && \
alias cls="printf '\ec'" || \
alias cls="clear && printf '\e[3J'"
alias ls='ls -F --color=auto'
if which cgdb &> /dev/null; then
if command -v cgdb &> /dev/null; then
alias debug='cgdb --args'
elif which gdb &> /dev/null; then
elif command -v gdb &> /dev/null; then
alias debug='gdb --args'
fi
;;
Darwin)
alias cls="clear && printf '\e[3J'"
alias ls='ls -GFh'
which lldb &> /dev/null && \
command -v lldb &> /dev/null && \
alias debug='lldb --'
;;
esac