Initial commit

This commit is contained in:
Mats Rauhala 2021-11-16 16:17:57 +02:00
commit 6969c15cdc
8 changed files with 704 additions and 0 deletions

25
flake.lock Normal file
View File

@ -0,0 +1,25 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1637069050,
"narHash": "sha256-aHrgiXjqBFUJuDDaekwzS1QA3EX5qDCe1/upPg1Vmo0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b464f0573e4e67978ed00a4bbab567a9bd08fc3c",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

117
flake.nix Normal file
View File

@ -0,0 +1,117 @@
{
description = "A very basic flake";
outputs = { self, nixpkgs }: {
nixosModule = { config, lib, pkgs, ... }:
with lib;
let cfg = config.programs.myZsh;
in
{
options = {
programs.myZsh = {
enable = mkEnableOption "Enable zsh";
};
};
config = mkIf cfg.enable {
programs.zsh = {
enable = true;
shellAliases = {
mkae = "make";
tw = "${pkgs.timewarrior}/bin/timew";
# ti = "${pkgs.timer}/bin/timer start $*";
# to = "${pkgs.timer}/bin/timer stop";
mutt = "${pkgs.neomutt}/bin/neomutt";
ls = "ls -N --color=auto";
# Play a sound of "rolling waves"
# Taken from https://askubuntu.com/a/789472
# The 0.2 is the time for a wive
# The 30 is the minimum amplitude
# The amod means amplitude modulation
noise = "${pkgs.sox}/bin/play -n synth brownnoise synth pinknoise mix synth sine amod 0.2 30";
ed = "${pkgs.myEmacs}/bin/emacsclient -c";
};
enableAutosuggestions = true;
sessionVariables = {
EDITOR = "${pkgs.myVim}/bin/vim";
PAGER = "less";
};
history = {
save = 100000;
size = 102000;
ignoreDups = false;
expireDuplicatesFirst = true;
extended = true;
share = true;
path = ".zhistory";
};
# http://zsh.sourceforge.net/Intro/intro_3.html
# .zlogin is meant for programs to start on login shells
# It is not meant for setting up aliases etc.
# On the other hand, .zlogin is only invoked at *login*.
initExtra = ''
bindkey -v
autoload -U edit-command-line
zle -N edit-command-line
bindkey "^?" backward-delete-char
bindkey '^[OH' beginning-of-line
bindkey '^[OF' end-of-line
bindkey '^[[5~' up-line-or-history
bindkey '^[[6~' down-line-or-history
bindkey '^[[B' history-search-forward
bindkey '^[[A' history-search-backward
bindkey "^r" history-incremental-search-backward
bindkey ' ' magic-space # also do history expansion on space
bindkey '^E' complete-word # complete on tab, leave expansion to _expand
bindkey ^e edit-command-line
setopt prompt_sp # print lines without newlines properly
eval "$(direnv hook zsh)"
case $TERM in
termite|*xterm*|rxvt|rxvt-unicode|rxvt-256color|rxvt-unicode-256color|(dt|k|E)term)
precmd () { print -Pn "\e]0;$(pwd)\a" }
preexec () { print -Pn "\e]0;$1\a" }
;;
screen|screen-256color)
precmd () {
print -Pn "\e]83;title \"$1\"\a"
print -Pn "\e]0;$TERM\a"
}
preexec () {
print -Pn "\e]83;title \"$1\"\a"
print -Pn "\e]0;$TERM - $1\a"
}
;;
esac
wttr()
{
local request="wttr.in/''${1-Espoo}?M"
[ "$(tput cols)" -lt 125 ] && request+='&n'
curl -H "Accept-Language: ''${LANG%_*}" --compressed "$request"
}
totp()
{
${pkgs.oathToolkit}/bin/oathtool --totp --base32 $(${pkgs.pass}/bin/pass show $1)
}
${pkgs.remind}/bin/rem
'';
plugins = [
{
name = "wunjo";
src = ./zsh/wunjo;
}
{
name = "gwp";
src = ./zsh/gwp;
}
];
};
};
};
};
}

View File

@ -0,0 +1,2 @@
export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -200'"
export FZF_CTRL_T_OPTS="(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null | head -200'"

9
zsh/gwp/gwp.plugin.zsh Normal file
View File

@ -0,0 +1,9 @@
function gwp() {
pkgs="$@"
nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz -p "ghcid" -p "haskellPackages.ghcWithHoogle (pkgs: with pkgs; [$pkgs])" --run 'zsh'
}
function gwi() {
pkgs="$@"
nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [$pkgs])" --run 'ghci'
}

2
zsh/totp/totp.plugin.zsh Normal file
View File

@ -0,0 +1,2 @@
function totp () {
}

View File

@ -0,0 +1,303 @@
# wunjo prompt theme
# Modified by MasseR to include the battery script
autoload -U zgitinit
zgitinit
prompt_wunjo_help () {
cat <<'EOF'
prompt wunjo
EOF
}
revstring() {
git describe --tags --always $1 2>/dev/null ||
git rev-parse --short $1 2>/dev/null
}
coloratom() {
local off=$1 atom=$2
if [[ $atom[1] == [[:upper:]] ]]; then
off=$(( $off + 60 ))
fi
echo $(( $off + $colorcode[${(L)atom}] ))
}
colorword() {
local fg=$1 bg=$2 att=$3
local -a s
if [ -n "$fg" ]; then
s+=$(coloratom 30 $fg)
fi
if [ -n "$bg" ]; then
s+=$(coloratom 40 $bg)
fi
if [ -n "$att" ]; then
s+=$attcode[$att]
fi
echo "%{"$'\e['${(j:;:)s}m"%}"
}
prompt_wunjo_setup() {
local verbose
if [[ $TERM == screen* ]] && [ -n "$STY" ]; then
verbose=
else
verbose=1
fi
typeset -A colorcode
colorcode[black]=0
colorcode[red]=1
colorcode[green]=2
colorcode[yellow]=3
colorcode[blue]=4
colorcode[magenta]=5
colorcode[cyan]=6
colorcode[white]=7
colorcode[default]=9
colorcode[k]=$colorcode[black]
colorcode[r]=$colorcode[red]
colorcode[g]=$colorcode[green]
colorcode[y]=$colorcode[yellow]
colorcode[b]=$colorcode[blue]
colorcode[m]=$colorcode[magenta]
colorcode[c]=$colorcode[cyan]
colorcode[w]=$colorcode[white]
colorcode[.]=$colorcode[default]
typeset -A attcode
attcode[none]=00
attcode[bold]=01
attcode[faint]=02
attcode[standout]=03
attcode[underline]=04
attcode[blink]=05
attcode[reverse]=07
attcode[conceal]=08
attcode[normal]=22
attcode[no-standout]=23
attcode[no-underline]=24
attcode[no-blink]=25
attcode[no-reverse]=27
attcode[no-conceal]=28
local -A pc
pc[default]='default'
pc[date]='cyan'
pc[time]='Blue'
pc[host]='Green'
pc[user]='cyan'
pc[punc]='yellow'
pc[line]='magenta'
pc[hist]='green'
pc[path]='Cyan'
pc[shortpath]='default'
pc[rc]='red'
pc[remote]='red'
pc[scm_branch]='Cyan'
pc[scm_commitid]='Yellow'
pc[scm_status_dirty]='Red'
pc[scm_status_staged]='Green'
pc[#]='Yellow'
for cn in ${(k)pc}; do
pc[${cn}]=$(colorword $pc[$cn])
done
pc[reset]=$(colorword . . 00)
typeset -Ag wunjo_prompt_colors
wunjo_prompt_colors=(${(kv)pc})
local p_date p_line p_rc
p_date="$pc[date]%D{%Y-%m-%d} $pc[time]%D{%T}$pc[reset]"
p_line="$pc[line]%y$pc[reset]"
PROMPT=
# Add indication if remote
if [ ! -e $SSH_CLIENT ]; then
host=$(echo $SSH_CLIENT | cut -f1 -d " ")
PROMPT+="$pc[remote]($host)$pc[reset]"
fi
# Add indication if nix shell
if [ ! -e $IN_NIX_SHELL ]; then
PROMPT+="$pc[nix]($IN_NIX_SHELL)$pc[reset]"
fi
if [ $verbose ]; then
PROMPT+="$pc[host]%m$pc[reset] "
fi
PROMPT+="$pc[path]%(2~.%~.%/)$pc[reset]"
PROMPT+="\$(prompt_wunjo_scm_status)"
PROMPT+="%(?.. $pc[rc]exited %1v$pc[reset])"
PROMPT+="
"
PROMPT+="$pc[hist]%h$pc[reset] "
PROMPT+="$pc[shortpath]%1~$pc[reset]"
PROMPT+="\$(prompt_wunjo_scm_branch)"
PROMPT+=" $pc[#]%#$pc[reset] "
export PROMPT
add-zsh-hook precmd prompt_wunjo_precmd
}
prompt_wunjo_precmd() {
local ex=$?
psvar=()
if [ -e /proc/acpi/battery/BAT0 ]; then
battery=$(~/bin/zsh-battery)
RPROMPT=$battery
fi
if [[ $ex -ge 128 ]]; then
sig=$signals[$ex-127]
psvar[1]="sig${(L)sig}"
else
psvar[1]="$ex"
fi
}
prompt_wunjo_scm_status() {
zgit_isgit || return
local -A pc
pc=(${(kv)wunjo_prompt_colors})
head=$(zgit_head)
gitcommit=$(revstring $head)
local -a commits
if zgit_rebaseinfo; then
orig_commit=$(revstring $zgit_info[rb_head])
orig_name=$(git name-rev --name-only $zgit_info[rb_head])
orig="$pc[scm_branch]$orig_name$pc[punc]($pc[scm_commitid]$orig_commit$pc[punc])"
onto_commit=$(revstring $zgit_info[rb_onto])
onto_name=$(git name-rev --name-only $zgit_info[rb_onto])
onto="$pc[scm_branch]$onto_name$pc[punc]($pc[scm_commitid]$onto_commit$pc[punc])"
if [ -n "$zgit_info[rb_upstream]" ] && [ $zgit_info[rb_upstream] != $zgit_info[rb_onto] ]; then
upstream_commit=$(revstring $zgit_info[rb_upstream])
upstream_name=$(git name-rev --name-only $zgit_info[rb_upstream])
upstream="$pc[scm_branch]$upstream_name$pc[punc]($pc[scm_commitid]$upstream_commit$pc[punc])"
commits+="rebasing $upstream$pc[reset]..$orig$pc[reset] onto $onto$pc[reset]"
else
commits+="rebasing $onto$pc[reset]..$orig$pc[reset]"
fi
local -a revs
revs=($(git rev-list $zgit_info[rb_onto]..HEAD))
if [ $#revs -gt 0 ]; then
commits+="\n$#revs commits in"
fi
if [ -f $zgit_info[dotest]/message ]; then
mess=$(head -n1 $zgit_info[dotest]/message)
commits+="on $mess"
fi
elif [ -n "$gitcommit" ]; then
commits+="on $pc[scm_branch]$head$pc[punc]($pc[scm_commitid]$gitcommit$pc[punc])$pc[reset]"
local track_merge=$(zgit_tracking_merge)
if [ -n "$track_merge" ]; then
if git rev-parse --verify -q $track_merge >/dev/null; then
local track_remote=$(zgit_tracking_remote)
local tracked=$(revstring $track_merge 2>/dev/null)
local -a revs
revs=($(git rev-list --reverse $track_merge..HEAD))
if [ $#revs -gt 0 ]; then
local base=$(revstring $revs[1]~1)
local base_name=$(git name-rev --name-only $base)
local base_short=$(revstring $base)
local word_commits
if [ $#revs -gt 1 ]; then
word_commits='commits'
else
word_commits='commit'
fi
local conj="since"
if [[ "$base" == "$tracked" ]]; then
conj+=" tracked"
tracked=
fi
commits+="$#revs $word_commits $conj $pc[scm_branch]$base_name$pc[punc]($pc[scm_commitid]$base_short$pc[punc])$pc[reset]"
fi
if [ -n "$tracked" ]; then
local track_name=$track_merge
if [[ $track_remote == "." ]]; then
track_name=${track_name##*/}
fi
tracked=$(revstring $tracked)
commits+="tracking $pc[scm_branch]$track_name$pc[punc]"
if [[ "$tracked" != "$gitcommit" ]]; then
commits[$#commits]+="($pc[scm_commitid]$tracked$pc[punc])"
fi
commits[$#commits]+="$pc[reset]"
fi
fi
fi
fi
gitsvn=$(git rev-parse --verify -q --short git-svn)
if [ $? -eq 0 ]; then
gitsvnrev=$(zgit_svnhead $gitsvn)
gitsvn=$(revstring $gitsvn)
if [ -n "$gitsvnrev" ]; then
local svninfo=''
local -a revs
svninfo+="$pc[default]svn$pc[punc]:$pc[scm_branch]r$gitsvnrev"
revs=($(git rev-list git-svn..HEAD))
if [ $#revs -gt 0 ]; then
svninfo+="$pc[punc]@$pc[default]HEAD~$#revs"
svninfo+="$pc[punc]($pc[scm_commitid]$gitsvn$pc[punc])"
fi
commits+=$svninfo
fi
fi
if [ $#commits -gt 0 ]; then
echo -n " ${(j: :)commits}"
fi
}
prompt_wunjo_scm_branch() {
zgit_isgit || return
local -A pc
pc=(${(kv)wunjo_prompt_colors})
echo -n "$pc[punc]:$pc[scm_branch]$(zgit_head)"
if zgit_inworktree; then
if ! zgit_isindexclean; then
echo -n "$pc[scm_status_staged]+"
fi
local -a dirty
if ! zgit_isworktreeclean; then
dirty+='!'
fi
if zgit_hasunmerged; then
dirty+='*'
fi
if zgit_hasuntracked; then
dirty+='?'
fi
if [ $#dirty -gt 0 ]; then
echo -n "$pc[scm_status_dirty]${(j::)dirty}"
fi
fi
echo $pc[reset]
}
prompt_wunjo_setup "$@"
# vim:set ft=zsh:

View File

@ -0,0 +1,2 @@
setopt PROMPT_SUBST
source prompt_wunjo_setup

244
zsh/wunjo/zgitinit Normal file
View File

@ -0,0 +1,244 @@
##
## Load with `autoload -U zgitinit; zgitinit'
##
typeset -gA zgit_info
zgit_info=()
zgit_chpwd_hook() {
zgit_info_update
}
zgit_preexec_hook() {
if [[ $2 == git\ * ]] || [[ $2 == *\ git\ * ]]; then
zgit_precmd_do_update=1
fi
}
zgit_precmd_hook() {
if [ $zgit_precmd_do_update ]; then
unset zgit_precmd_do_update
zgit_info_update
fi
}
zgit_info_update() {
zgit_info=()
local gitdir="$(git rev-parse --git-dir 2>/dev/null)"
if [ $? -ne 0 ] || [ -z "$gitdir" ]; then
return
fi
zgit_info[dir]=$gitdir
zgit_info[bare]=$(git rev-parse --is-bare-repository)
zgit_info[inwork]=$(git rev-parse --is-inside-work-tree)
}
zgit_isgit() {
if [ -z "$zgit_info[dir]" ]; then
return 1
else
return 0
fi
}
zgit_inworktree() {
zgit_isgit || return
if [ "$zgit_info[inwork]" = "true" ]; then
return 0
else
return 1
fi
}
zgit_isbare() {
zgit_isgit || return
if [ "$zgit_info[bare]" = "true" ]; then
return 0
else
return 1
fi
}
zgit_head() {
zgit_isgit || return 1
if [ -z "$zgit_info[head]" ]; then
local name=''
name=$(git symbolic-ref -q HEAD)
if [ $? -eq 0 ]; then
if [[ $name == refs/(heads|tags)/* ]]; then
name=${name#refs/(heads|tags)/}
fi
else
name=$(git name-rev --name-only --no-undefined --always HEAD)
if [ $? -ne 0 ]; then
return 1
elif [[ $name == remotes/* ]]; then
name=${name#remotes/}
fi
fi
zgit_info[head]=$name
fi
echo $zgit_info[head]
}
zgit_branch() {
zgit_isgit || return 1
zgit_isbare && return 1
if [ -z "$zgit_info[branch]" ]; then
local branch=$(git symbolic-ref HEAD 2>/dev/null)
if [ $? -eq 0 ]; then
branch=${branch##*/}
else
branch=$(git name-rev --name-only --always HEAD)
fi
zgit_info[branch]=$branch
fi
echo $zgit_info[branch]
return 0
}
zgit_tracking_remote() {
zgit_isgit || return 1
zgit_isbare && return 1
local branch
if [ -n "$1" ]; then
branch=$1
elif [ -z "$zgit_info[branch]" ]; then
branch=$(zgit_branch)
[ $? -ne 0 ] && return 1
else
branch=$zgit_info[branch]
fi
local k="tracking_$branch"
local remote
if [ -z "$zgit_info[$k]" ]; then
remote=$(git config branch.$branch.remote)
zgit_info[$k]=$remote
fi
echo $zgit_info[$k]
return 0
}
zgit_tracking_merge() {
zgit_isgit || return 1
zgit_isbare && return 1
local branch
if [ -z "$zgit_info[branch]" ]; then
branch=$(zgit_branch)
[ $? -ne 0 ] && return 1
else
branch=$zgit_info[branch]
fi
local remote=$(zgit_tracking_remote $branch)
[ $? -ne 0 ] && return 1
if [ -n "$remote" ]; then # tracking branch
local merge=$(git config branch.$branch.merge)
if [ $remote != "." ]; then
merge=$remote/$(basename $merge)
fi
echo $merge
return 0
else
return 1
fi
}
zgit_isindexclean() {
zgit_isgit || return 1
if git diff --quiet --cached 2>/dev/null; then
return 0
else
return 1
fi
}
zgit_isworktreeclean() {
zgit_isgit || return 1
if [ -z "$(git ls-files --modified)" ]; then
return 0
else
return 1
fi
}
zgit_hasuntracked() {
zgit_isgit || return 1
local -a flist
flist=($(git ls-files --others --exclude-standard))
if [ $#flist -gt 0 ]; then
return 0
else
return 1
fi
}
zgit_hasunmerged() {
zgit_isgit || return 1
local -a flist
flist=($(git ls-files -u))
if [ $#flist -gt 0 ]; then
return 0
else
return 1
fi
}
zgit_svnhead() {
zgit_isgit || return 1
local commit=$1
if [ -z "$commit" ]; then
commit='HEAD'
fi
git svn find-rev $commit
}
zgit_rebaseinfo() {
zgit_isgit || return 1
if [ -d $zgit_info[dir]/rebase-merge ]; then
dotest=$zgit_info[dir]/rebase-merge
elif [ -d $zgit_info[dir]/.dotest-merge ]; then
dotest=$zgit_info[dir]/.dotest-merge
elif [ -d .dotest ]; then
dotest=.dotest
else
return 1
fi
zgit_info[dotest]=$dotest
zgit_info[rb_onto]=$(cat "$dotest/onto")
if [ -f "$dotest/upstream" ]; then
zgit_info[rb_upstream]=$(cat "$dotest/upstream")
else
zgit_info[rb_upstream]=
fi
if [ -f "$dotest/orig-head" ]; then
zgit_info[rb_head]=$(cat "$dotest/orig-head")
elif [ -f "$dotest/head" ]; then
zgit_info[rb_head]=$(cat "$dotest/head")
fi
zgit_info[rb_head_name]=$(cat "$dotest/head-name")
return 0
}
add-zsh-hook chpwd zgit_chpwd_hook
add-zsh-hook preexec zgit_preexec_hook
add-zsh-hook precmd zgit_precmd_hook
zgit_info_update
# vim:set ft=zsh: