diff --git a/config.nix b/config.nix index 47884f4..06270f7 100644 --- a/config.nix +++ b/config.nix @@ -1,74 +1,78 @@ { config, lib, pkgs, ... }: let - fullName = "Kierán Meinhardt"; - fullEmail = "kieran.meinhardt@gmail.com"; theme = { - # gtk = { name = "Adwaita"; package = pkgs.gnome3.gnome_themes_standard; }; - gtk = { name = "Numix-SX-FullDark"; package = pkgs.numix-sx-gtk-theme; }; + gtk = { name = "Numix-SX-Dark"; package = pkgs.numix-sx-gtk-theme; }; icon = { name = "Papirus-Adapta-Nokto"; package = pkgs.papirus-icon-theme; }; - # icon = { name = "Adwaita"; package = pkgs.gnome3.adwaita-icon-theme; }; }; defaultApplications = { terminal = "${pkgs.xfce.terminal}/bin/xfce4-terminal"; - webBrowser = "${pkgs.google-chrome}/bin/google-chrome-stable"; + webBrowser = "${pkgs.chromium}/bin/chromium-browser"; fileManager = "${pkgs.gnome3.nautilus}/bin/nautilus"; + screenLocker = with import ./theme.nix; + "${pkgs.i3lock}/bin/i3lock -e -c ${lib.strings.removePrefix "#" black}"; }; wallpaper = pkgs.copyPathToStore ./art/haskell-grey.png; + scripts = import ./dot/scripts.nix pkgs defaultApplications; + constants = import ./constants.nix; in { imports = [ "${builtins.fetchTarball https://github.com/rycee/home-manager/archive/master.tar.gz}/nixos" ]; nixpkgs.config = { - packageOverrides = - let nix-writers = builtins.fetchGit { - url = https://cgit.krebsco.de/nix-writers/; - ref = "tags/v2.1.0"; - }; in import "${nix-writers}/pkgs" pkgs; allowUnfree = true; + packageOverrides = + let nix-writers = builtins.fetchGit { url = https://cgit.krebsco.de/nix-writers/; ref = "tags/v2.1.0"; }; + in import "${nix-writers}/pkgs" pkgs; }; security.sudo.enable = true; + security.sudo.extraConfig = "Defaults insults"; + fonts.enableDefaultFonts = true; fonts.fonts = with pkgs; [ powerline-fonts roboto font-awesome-ttf fira-code eb-garamond lmodern ]; - environment.systemPackages = [ theme.icon.package theme.gtk.package] ++ (with pkgs; [ + + environment.systemPackages = with pkgs; [ + theme.icon.package theme.gtk.package ffmpeg mpv youtubeDL imagemagick zathura - google-chrome firefox lynx w3m firefoxPackages.tor-browser + chromium google-chrome firefox lynx w3m firefoxPackages.tor-browser lxappearance libnotify xfce.terminal - xorg.xbacklight pamixer + pamixer gnome3.nautilus git ripgrep tree whois - wget htop zip unzip tmux + wget htop zip unzip rlwrap pmount gnumake - ]); + (import ./dot/vim.nix pkgs) + ]; users.users.kfm = { createHome = true; - description = fullName; - extraGroups = [ "wheel" "networkmanager" ]; + description = constants.user.name; + extraGroups = [ "wheel" ]; group = "users"; home = "/home/kfm"; shell = pkgs.zsh; password = "kfm"; packages = with pkgs; [ - texlive.combined.scheme-minimal + texlive.combined.scheme-tetex franz grive2 gnuplot maxima libreoffice-fresh kdeconnect - par haskellPackages.pandoc biber + par haskellPackages.pandoc haskellPackages.pandoc-citeproc biber + haskellPackages.hakyll spotify gnome3.gnome-music audacity calibre inkscape - stack haskellPackages.hasktags + stack haskellPackages.hasktags haskellPackages.hindent haskellPackages.ghcid haskellPackages.hoogle rustup gcc tinycc ctags python3 mypy @@ -77,58 +81,41 @@ in { nasm ocaml fsharp swiProlog haskellPackages.idris clojure racket-minimal - jdk scala + scala ]; }; + environment.variables.EDITOR = pkgs.lib.mkForce "vim"; environment.shellAliases = - let rlwrap = cmd: "${pkgs.rlwrap}/bin/rlwrap ${cmd}"; in - { - ip = "${pkgs.iproute}/bin/ip -c"; - vi = "vim"; - ocaml = rlwrap "${pkgs.ocaml}/bin/ocaml"; - tmux = "${pkgs.tmux}/bin/tmux -2"; - clipboard = "${pkgs.xclip}/bin/xclip -se c"; - ghc = "${pkgs.stack}/bin/stack ghc --"; - ghci = "${pkgs.stack}/bin/stack ghc -- --interactive"; - external-ip = "${pkgs.dnsutils}/bin/dig +short myip.opendns.com @resolver1.opendns.com"; - }; + let rlwrap = cmd: "${pkgs.rlwrap}/bin/rlwrap ${cmd}"; + in { + ":r" = ''echo "You stupid!"''; + chrome-no-traces = "${pkgs.google-chrome}/bin/google-chrome-stable -incognito --user-data-dir=$HOME/.config/google-chrome/Incognito --disk-cache-dir=/dev/null --disk-cache-size=1"; + clipboard = "${pkgs.xclip}/bin/xclip -se c"; + external-ip = "${pkgs.dnsutils}/bin/dig +short myip.opendns.com @resolver1.opendns.com"; + ghc = "${pkgs.stack}/bin/stack ghc --"; + ghci = "${pkgs.stack}/bin/stack ghc -- --interactive"; + ip = "${pkgs.iproute}/bin/ip -c"; + ocaml = rlwrap "${pkgs.ocaml}/bin/ocaml"; + tmux = "${pkgs.tmux}/bin/tmux -2"; + vi = "vim"; + } // scripts; - programs.slock.enable = true; - - services.xserver = { + services.xserver = with import ./constants.nix; { enable = true; - layout = "de, gr, ru"; - xkbVariant = "T3, polytonic, phonetic_winkeys"; - xkbOptions = "terminate:ctrl_alt_bksp, grp:alt_space_toggle"; + layout = commaSep [ "de" "gr" "ru" ]; + xkbVariant = commaSep [ "T3" "polytonic" "phonetic_winkeys" ]; + xkbOptions = commaSep [ "terminate:ctrl_alt_bksp" "grp:alt_space_toggle" ]; libinput.enable = true; xautolock = { enable = true; time = 15; - locker = "${pkgs.slock}/bin/slock"; - nowlocker = "${pkgs.slock}/bin/slock"; + locker = defaultApplications.screenLocker; + nowlocker = defaultApplications.screenLocker; enableNotifier = true; - notifier = ''${pkgs.libnotify}/bin/notify-send "Locking soon."''; + notifier = ''${pkgs.libnotify}/bin/notify-send -u normal -a xautolock "Locking soon" "The screen will lock in 10 seconds."''; }; - /* - displayManager.lightdm = { - enable = true; - background = wallpaper; - greeters.gtk = { - clock-format = "%F"; - iconTheme = theme.icon; - theme = theme.gtk; - extraConfig = with import ./theme.nix; '' - font-name = ${uiFont.name} ${toString uiFont.size} - xft-antialias = true - xft-dpi = 96 - xft-hintstyle = slight - xft-rgba = rgb - ''; - }; - }; - */ displayManager.auto = { enable = true; user = "kfm"; @@ -138,22 +125,37 @@ in { windowManager.default = "i3"; windowManager.i3 = { enable = true; - configFile = pkgs.writeText "i3.conf" (import ./dot/i3.nix { - inherit pkgs defaultApplications wallpaper; - }); + configFile = pkgs.writeText "i3.conf" (import ./dot/i3.nix pkgs defaultApplications); + extraPackages = []; }; }; - i18n.consoleUseXkbConfig = true; + i18n = { + defaultLocale = "en_GB.UTF-8"; + consoleUseXkbConfig = true; + consoleColors = with import ./theme.nix; map (c: lib.strings.removePrefix "#" c) colorPalette; + }; + + services.cron = { + enable = true; + systemCronJobs = [ + "0 18 * * * ${scripts.bing-wallpaper}" + ]; + }; services.compton = { enable = true; fade = true; shadow = true; + menuOpacity = "0.9"; + shadowOpacity = "0.5"; fadeDelta = 2; - menuOpacity = "0.95"; }; services.openssh.enable = true; + programs.ssh = { + startAgent = true; + knownHosts = []; + }; services.redshift = { enable = true; @@ -180,7 +182,7 @@ in { setopt PUSHD_TO_HOME ''; promptInit = '' - PROMPT="%{$fg_bold[white]%}%~ \$([[ \$? == 0 ]] && echo \"%{$fg_bold[blue]%}\" || echo \"%{$fg_bold[red]%}\")%#%{$reset_color%} " + PROMPT="%{$fg_bold[white]%}%~ \$([[ \$? == 0 ]] && echo \"%{$fg_bold[green]%}\" || echo \"%{$fg_bold[red]%}\")%#%{$reset_color%} " RPROMPT='$(git_prompt_info)' ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[cyan]%}" @@ -188,20 +190,41 @@ in { ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*" ''; ohMyZsh.enable = true; - ohMyZsh.plugins = [ "common-aliases" "git" "git-extras" "history" "jsontools" ]; + ohMyZsh.plugins = [ "common-aliases" ]; + }; programs.bash = { - promptInit = ''PS1="[\$(exit=\$?; [[ \$exit == 0 ]] && echo \"\[\033[1;32m\]\$exit\" || echo \"\033[1;31m\]\$exit\")$(tput sgr0)]$(tput bold) \w $(tput setaf 1)\$$(tput sgr0) ''; + promptInit = ''PS1="$(tput bold)\w \$([[ \$? == 0 ]] && echo \"\[\033[1;32m\]\" || echo \"\[\033[1;31m\]\")\$$(tput sgr0) ''; enableCompletion = true; }; - # programs.vim.defaultEditor = true; + programs.command-not-found.enable = true; - networking.networkmanager.enable = true; + programs.java.enable = true; + programs.light.enable = true; + + programs.tmux = { + enable = true; + extraTmuxConf = import ./dot/tmux.nix; + keyMode = "vi"; + terminal = "screen-256color"; + }; + + programs.nano.nanorc = import ./dot/nano.nix; + + # networking.hostName = "scardanelli"; + networking.hosts = { + "192.168.178.27" = [ "printer.local" ]; + }; + + networking.wireless.enable = true; + networking.wireless.networks = { + Aether = { psk = "Kein ding sei wo das wort gebricht."; }; + "Asoziales Netzwerk" = { psk = "WirFragenDichNicht"; }; + }; + networking.wireless.userControlled.enable = true; home-manager.users.kfm = { - programs.command-not-found.enable = true; - gtk = { enable = true; font = with import ./theme.nix; { package = pkgs.roboto; name = uiFont.name; }; @@ -211,8 +234,8 @@ in { programs.git = { enable = true; - userName = fullName; - userEmail = fullEmail; + userName = constants.user.name; + userEmail = constants.user.email; aliases = { br = "branch"; co = "checkout"; @@ -222,47 +245,9 @@ in { unstage = "reset HEAD --"; sdiff = "diff --staged"; last = "log -1 HEAD"; + pull-all = "!${scripts.git-pull-all}"; }; - ignores = [ "*~" ".stack-work/" "__pycache__/" ".mypy_cache/" "*.o" "*.hi" "*.aux" ]; - }; - - programs.vim = { - enable = true; - plugins = [ - "ctrlp" - "deoplete-rust" - "deoplete-nvim" - "idris-vim" - "latex-box" - "rust-vim" - "supertab" - "syntastic" - "tabular" - "typescript-vim" - "vim-airline" - "vim-airline-themes" - "vim-commentary" - "vim-eunuch" - "vim-fugitive" - "vim-gitgutter" - "vim-javascript" - "vim-nix" - "vim-pandoc" - "vim-pandoc-after" - "vim-pandoc-syntax" - "vim-repeat" - "vim-sensible" - "vim-startify" - "vim-surround" - ]; - settings = { - smartcase = true; - shiftwidth = 4; - tabstop = 4; - expandtab = true; - number = true; - }; - extraConfig = import ./dot/vim.nix; + ignores = constants.ignoredFiles; }; programs.rofi = with import ./theme.nix; { @@ -292,7 +277,7 @@ in { global = { transparency = 10; font = "${uiFont.name} ${toString uiFont.size}"; - geometry = "300x5-30+20"; + geometry = "200x5-30+20"; frame_color = veryDark; follow = "mouse"; indicate_hidden = true; @@ -326,12 +311,12 @@ in { urgency_low = { frame_color = veryDark; background = veryDark; - foreground = light; + foreground = gray.light; timeout = 5; }; urgency_normal = { frame_color = veryDark; - background = light; + background = gray.light; foreground = veryDark; timeout = 10; }; @@ -345,16 +330,13 @@ in { }; home.file = { - ".ghci".text = import ./dot/ghci.nix { inherit pkgs; }; - ".tmux.conf".text = import ./dot/tmux.nix; - ".stack/config.yaml".text = import ./dot/stack.nix { - githubUser = "kmein"; - inherit fullName fullEmail; - }; + ".background-image".source = wallpaper; + ".ghci".text = import ./dot/ghci.nix pkgs; + ".stack/config.yaml".text = import ./dot/stack.nix constants.user; ".config/zathura/zathurarc".text = "set selection-clipboard clipboard"; ".config/mpv/input.conf".text = import ./dot/mpv.nix; - ".config/xfce4/terminal/terminalrc".text = import ./dot/terminal.nix { inherit defaultApplications; }; - ".background-image".source = wallpaper; + ".config/xfce4/terminal/terminalrc".text = import ./dot/terminal.nix defaultApplications; + ".zshrc".text = "# nothing to see here"; }; }; } diff --git a/constants.nix b/constants.nix new file mode 100644 index 0000000..cacfa7d --- /dev/null +++ b/constants.nix @@ -0,0 +1,11 @@ +{ + commaSep = strs: builtins.concatStringsSep "," strs; + + ignoredFiles = [ "*~" ".stack-work/" "__pycache__/" ".mypy_cache/" "*.o" "*.hi" "*.aux" "*.class" "*.dyn_hi" "*.dyn_o" ]; + + user = { + github = "kmein"; + name = "Kierán Meinhardt"; + email = "kieran.meinhardt@gmail.com"; + }; +} diff --git a/dot/ghci.nix b/dot/ghci.nix index 942cd64..486215e 100644 --- a/dot/ghci.nix +++ b/dot/ghci.nix @@ -1,4 +1,4 @@ -{pkgs}: +pkgs: '' :set editor vim :def hoogle \x -> return $ ":!${pkgs.haskellPackages.hoogle}/bin/hoogle --color \"" ++ x ++ "\" " diff --git a/dot/i3.nix b/dot/i3.nix index 52484b2..50b8452 100644 --- a/dot/i3.nix +++ b/dot/i3.nix @@ -1,4 +1,4 @@ -{ pkgs, defaultApplications, wallpaper }: +pkgs: defaultApplications: let theme = import ../theme.nix; in with theme; '' @@ -71,8 +71,8 @@ bindsym $mod+Shift+9 move container to workspace $WS9 bindsym XF86AudioLowerVolume exec --no-startup-id ${pkgs.pamixer}/bin/pamixer -d 5 && pkill -RTMIN+3 i3blocks bindsym XF86AudioRaiseVolume exec --no-startup-id ${pkgs.pamixer}/bin/pamixer -i 5 && pkill -RTMIN+3 i3blocks bindsym XF86AudioMute exec --no-startup-id ${pkgs.pamixer}/bin/pamixer -t && pkill -RTMIN+3 i3blocks -bindsym XF86MonBrightnessUp exec --no-startup-id ${pkgs.xorg.xbacklight}/bin/xbacklight + 10 && pkill -RTMIN+2 i3blocks -bindsym XF86MonBrightnessDown exec --no-startup-id ${pkgs.xorg.xbacklight}/bin/xbacklight - 10 && pkill -RTMIN+2 i3blocks +bindsym XF86MonBrightnessUp exec --no-startup-id ${pkgs.light}/bin/light +A 10 && pkill -RTMIN+2 i3blocks +bindsym XF86MonBrightnessDown exec --no-startup-id ${pkgs.light}/bin/light -A 10 && pkill -RTMIN+2 i3blocks mode "  " { bindsym Left resize shrink width 10 px or 10 ppt @@ -113,6 +113,4 @@ bar { binding_mode ${black} ${black} ${red.light} } } - -exec --no-startup-id ${pkgs.networkmanagerapplet}/bin/nm-applet '' diff --git a/dot/i3blocks.nix b/dot/i3blocks.nix index 478f60b..70762a8 100644 --- a/dot/i3blocks.nix +++ b/dot/i3blocks.nix @@ -25,7 +25,8 @@ let printf "%s \u2237 %s" "$ARTIST" "$TITLE" ''; battery_info = pkgs.writeBash "battery.info" '' - cd "/sys/class/power_supply/$BLOCK_INSTANCE/" + BAT_DIR="/sys/class/power_supply/$BLOCK_INSTANCE/" + [ -d BAT_DIR ] && cd BAT_DIR || exit 1 status=$(cat status) charge_f=$((100 * $(cat charge_now) / $(cat charge_full))) @@ -89,11 +90,18 @@ let printf '\uf028 %s%%' "$volume" fi ''; - fancyDate = pkgs.writePython3 "fancy_date.py" {} '' - from datetime import datetime - now = datetime.now() - print(now.strftime("%d\u2009{}\u2009%Y ⟨%V⟩") - .format(chr(0x2160 + (now.month - 1)))) + fancyDate = pkgs.writeC "fancy_date.c" {} '' + #include + #include + #include + + int main(void) { + time_t now = time(NULL); + struct tm *today = localtime(&now); + wchar_t roman_month = 0x2160 + today->tm_mon; + wprintf(L"%d\u2009%lc\u2009%d [%d]\n", today->tm_mday, roman_month, 1900 + today->tm_year, today->tm_yday/7 + 1); + return 0; + } ''; in with theme; '' @@ -103,11 +111,6 @@ color=${white} [spotify] command=${spotify_info} -interval=1 - -[separator] -command=${pkgs.xkblayout-state}/bin/xkblayout-state print %s -label= interval=2 [separator] @@ -154,15 +157,20 @@ instance=BAT1 [date] command=${fancyDate} -interval=30 +interval=1 label= [separator] [time] command=date +'%H:%M' -interval=30 +interval=1 label= +[separator] +command=${pkgs.xkblayout-state}/bin/xkblayout-state print %s +label= +interval=2 + [separator] '' diff --git a/dot/nano.nix b/dot/nano.nix new file mode 100644 index 0000000..1ae00ad --- /dev/null +++ b/dot/nano.nix @@ -0,0 +1,8 @@ +'' + set autoindent + set boldtext + set morespace + set smarthome + set tabsize 4 + set tabstospaces +'' diff --git a/dot/scripts.nix b/dot/scripts.nix new file mode 100644 index 0000000..77d9886 --- /dev/null +++ b/dot/scripts.nix @@ -0,0 +1,650 @@ +pkgs: defaultApplications: +let + bingWallpaper = pkgs.writeBash "bing-wallpaper.sh" '' + PICTURE_DIR="$HOME/pictures/external/bing/" + + mkdir -p $PICTURE_DIR + + urls=( $(${pkgs.curl}/bin/curl -s http://www.bing.com \ + | grep -Eo "url:'.*?'" \ + | sed -e "s/url:'\([^']*\)'.*/http:\/\/bing.com\1/" \ + | sed -e "s/\\\//g") ) + + for p in ''${urls[@]}; do + filename=$(echo $p | sed -e "s/.*\/\(.*\)/\1/") + if [ ! -f $PICTURE_DIR/$filename ]; then + ${pkgs.curl}/bin/curl -Lo "$PICTURE_DIR/$filename" $p + fi + done + ''; + colorize = pkgs.writeBash "colorize.sh" '' + highlight=$(which highlight 2>/dev/null) + pygmentize=$(which pygmentize 2>/dev/null) + + colorize() { + if [ "$TERM" == "dumb" -o "$NO_COLORS" == "1" ] + then + cat + else + if [ "$1" == "haskell" ]; then + ${pkgs.haskellPackages.hscolour}/bin/HsColour -tty + else + ${pkgs.python36Packages.pygments}/bin/pygmentize -l $1 -O bg=dark + fi + fi + } + + if [ -z "$2" ]; then + colorize "$1" + else + cat "$2" | colorize "$1" + fi + ''; + easyBackup = pkgs.writeBash "easy-backup.sh" '' + if [ -d "$1" ]; then + OUTPUT_ROOT=''${1}/backup/current + rsync -hav --delete --stats --progress --exclude-from=$HOME/bin/backup.exclude $HOME/* $OUTPUT_ROOT/ + else + echo "No backup directory supplied" + exit 1 + fi + ''; + compile = pkgs.writeBash "compile.sh" '' + if [ -z "$1" ]; then + echo "Usage: compile " + fi + + file="$1" + ext="''${file##*.}" + name="''${file%.*}" + + case "$ext" in + asm) + echo Compiling "$name" with the Netwide Assembler... + nasm -felf64 -o "$name".o "$file" + gcc -o "$name" "$name".o;; + c) + echo Compiling "$name" with the GNU C Compiler... + gcc -std=c11 -Wall -Wpedantic -Ofast -o "$name" "$file";; + cpp|cxx|cc) + echo Compiling "$name" with the GNU C++ Compiler... + g++ -std=c++11 -Wall -O3 -o "$name" "$file";; + bf) + echo Compiling "$name" with the BrainFuck Compiler... + bf2c "$file" "$name".c && compile "$name".c && rm "$name".c;; + s) + echo Assembling "$name" with the GNU Assembler... + gcc -o "$name" "$file";; + hs) + echo Compiling "$name" with the Glasgow Haskell Compiler... + stack ghc -- -Wall -O3 --make "$file" && rm "$name".hi "$name".o;; + java) + echo Compiling "$name" with the Oracle Java Compiler... + javac "$file";; + rb) + echo Compiling "$name" with Ruby... + ruby -c "$file";; + lua) + echo Compiling "$name" with the Lua Compiler... + luac -o "$name".luac "$file";; + py) + if [ ""$2"" = "--optimize" ]; then + echo Compiling "$name" with the optimizing Python Compiler... + if [ -e "$name".pyo ]; then + rm "$name".pyo + fi + python3 -O -mpy_compile "$file" + mv __pycache__/"$name".cpython-33.pyo ./"$name".pyo + rmdir __pycache__ + else + echo Compiling "$name" with the Python Compiler... + if [ -e "$name".pyc ]; then + rm "$name".pyc + fi + python3 -mpy_compile "$file" + mv __pycache__/"$name".cpython-33.pyc ./"$name".pyc + rmdir __pycache__ + fi;; + ml) + echo Compiling "$name" with the OCaml Compiler... + ocamlc -o "$name" "$file" && rm "$name".cmo "$name".cmi;; + cs) + echo Compiling "$name" with the Mono C£ Compiler... + mono-csc -out:"$name" "$file";; + fs) + echo Compiling "$name" with the F£ Compiler... + fsharpc -out:"$name" "$file";; + vala) + echo Compiling "$name" with the Vala Compiler... + valac --pkg=gtk+-3.0 "$file";; + md) + echo Converting "$name" to PDF with Pandoc... + pandoc --latex-engine=xelatex -V documentclass=scrartcl -o "$name".pdf "$file";; + tex) + echo Compiling "$name" to PDF with LaTeX... + latexmk -pdf "$file";; + lhs) + echo Compiling "$name" with the Glasgow Haskell Compiler... + ghc -Wall -O3 --make "$file" + echo Converting "$name" to PDF Markup with Pandoc... + pandoc "$file" -f markdown+lhs --latex-engine=xelatex -V documentclass=scrartcl -o "$name".pdf;; + d) + echo Compiling "$name" with the GNU D Compiler... + gdc -Wall -O3 -o "$name" "$file";; + m) + echo Compiling "$name" with the GNU/GNUstep Objective C Compiler... + £ gcc -Wall -o "$name" -MMD -MP -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1 -fno-strict-aliasing -fexceptions -fobjc-exceptions -D_NATIVE_OBJC_EXCEPTIONS -pthread -fPIC -DGSWARN -Wno-import -g -O2 -fgnu-runtime -fconstant-string-class=NSConstantString -fexec-charset=UTF-8 -I. -I/usr/local/include/GNUstep -I/usr/include/GNUstep -lobjc -lgnustep-base "$file" + gcc `gnustep-config --objc-flags` "$file" -o "$name" -lgnustep-base -lobjc + ;; + pas) + echo Compiling "$name" with the FreePascal Compiler... + fpc "$file";; + rs) + echo Compiling "$name" with the Rust Compiler... + rustc "$file";; + ts) + echo Compiling "$name" with the TypeScript Compiler... + tsc "$file";; + *) + echo Compiler for "$ext" not found!;; + esac + ''; + gitPullAll = pkgs.writeBash "git-pull-all.sh" '' + # store the current dir + CUR_DIR=$(pwd) + # Let the person running the script know what's going on. + echo -e "\n\033[1mPulling in latest changes for all repositories...\033[0m\n" + # Find all git repositories and update it to the master latest revision + for i in $(find . -name ".git" | cut -c 3-); do + echo ""; + echo -e "\033[33m"+$i+"\033[0m"; + # We have to go to the .git parent directory to call the pull command + cd "$i"; + cd ..; + # finally pull + git pull origin master; + # lets get back to the CUR_DIR + cd $CUR_DIR + done + echo -e "\n\033[32mComplete!\033[0m\n" + ''; + gripe = pkgs.writeBash "gripe.sh" ''${sidepipe} '(:\d+:|-\d+-|--)(\x1b[[]K)?' "$@"''; + haskellDefinition = pkgs.writeBash "hdef.sh" '' + paths="" + while true; do + if [ -d "$1" ]; then + paths="$paths $1" + else + break + fi + shift + done + str="$1" + shift + + lower=$(echo "$str" | tr A-Z a-z) + if [ "''${lower:0:1}" == "''${str:0:1}" ]; then + expr="($str( |$)|[[:space:]]+$str[[:space:]]*::)" + else + kws="(class|data|type|newtype)" + eow="([ \n\t]|$)" + expr="$kws[[:space:]]+($str$eow|[^=]+=>[[:space:]]+$str$eow)" + fi + + ${haskellFind} $paths -print0 | xargs -0 grep -En --colour=never -A10 "$@" "^$expr" | ${gripe} hcol | ${highlight} $str + ''; + haskellFind = pkgs.writeBash "hfind.sh" '' + paths="" + while true; do + if [ -d "$1" ]; then + paths="$paths $1" + else + break + fi + shift + done + find $paths \( -name "*.hs" -or -name "*.hsi" -or -name "*.lhs" -or -name "*.hs-boot" \) -a -not \( -name ".*" -or -path "*/_darcs/*" -o -name '.£*' \) "$@" + ''; + haskellGrep = pkgs.writeBash "hgrep.sh" '' + if [ -z "$1" -o "$1" == "--help" -o "$1" == "-h" ]; then + echo "Usage: hg [PATH] IDENTIFIER [GREP OPTIONS...]" + echo "Seaches for uses of the given Haskell identifier." + exit 1 + fi + + paths="" + while true; do + if [ -d "$1" ]; then + paths="$paths $1" + else + break + fi + shift + done + + colour=always + if [ "$TERM" == "dumb" -o "$NO_COLORS" == "1" ]; then + colour=never + fi + ${haskellFind} $paths -print0 | xargs -0 grep -nw --colour=$colour "$@" + ''; + highlight = pkgs.writePython3 "hl.py" { + deps = [ pkgs.python36Packages.ansicolors ]; + flakeIgnore = [ "E302" "E999" "E231" "E701" "W605" "E231" "E305" ]; + } '' + import os + import sys + import re + from ansicolors import * + + def replfun((re,colfun)): + def onmatch(m): + if m.groups() != (): + buf = [] + p = m.start(0) + mstr = m.string + try: + i = 1 + while True: + (s,e) = m.span(i) + if s == -1: continue + buf.append(mstr[p:s]) + buf.append(colfun(mstr[s:e])) + p = e + i += 1 + except IndexError: + buf.append(mstr[p:m.end(0)]) + return '\'.join(buf) + else: + return colfun(m.expand("\g<0>")) + return lambda s: re.subn(onmatch,s)[0] + + colfuns = [green, red, magenta, cyan, blue] + flags = re.L + if len(sys.argv) > 1 and sys.argv[1] == '-i': + flags = flags | re.I + exps = sys.argv[2:] + else: + exps = sys.argv[1:] + regexps = map(lambda e: re.compile(e, flags), exps) + hlfuns = map(replfun, zip(regexps, colfuns)) + + term = os.getenv("TERM") + no_colors = os.getenv("NO_COLORS") + if term == "dumb" or no_colors == "1": + for line in sys.stdin: + sys.stdout.write(line) + else: + for line in sys.stdin: + sys.stdout.write(reduce(lambda s, f: f(s), hlfuns, line)) + ''; + haskellTags = pkgs.writeBash "htags.sh" '' + id="[a-z_][a-zA-Z0-9_\']*" + ws="[ \\t]" + ID="[A-Z][a-zA-Z0-9_\']*" + + ${pkgs.ctags}/bin/ctags --tag-relative=no \ + '--langdef=haskell' \ + '--langmap=haskell:.hs.lhs' \ + '--regex-haskell=/^(type|data|newtype)[ \t]+([^ \t=]+)/\2/' \ + '--regex-haskell=/^class[^=]+=>[ \t]*([^ \t]+)/\1/' \ + '--regex-haskell=/^class[ \t]+([^ \t]+)[^=]*$/\1/' \ + "--regex-haskell=/^$ws*($id)$ws*::/\1/" \ + "--regex-haskell=/^($id)/\1/" \ + "$@" + ''; + sidepipe = pkgs.writePython3 "sidepipe.py" { flakeIgnore = [ "E302" "E231" "E999" "E265" "E305" ]; } '' + import sys + import re + import os.path + from Queue import Queue + from subprocess import Popen, PIPE + from threading import Thread + + pipeIsLeft = os.path.basename(sys.argv[0]) == "leftpipe" + regex = sys.argv[1] + cmd = sys.argv[2:] + + class WorkerThread(Thread): + def __init__(self, queue, instream, outstream, pipeIsLeft): + Thread.__init__(self) + self.queue = queue + self.instream = instream + self.outstream = outstream + self.pipeIsLeft = pipeIsLeft + + class SplitThread(WorkerThread): + def run(self): + try: + for line in self.instream: + match = re.search(regex,line) + if not match: + print >> sys.stderr, "No match: %r in %r" % (regex,line) + continue + index = match.end() + left, right = line[:index], line[index:] + if pipeIsLeft: + self.outstream.write(left) + self.queue.put(right) + else: + self.outstream.write(right) + self.queue.put(left) + self.outstream.close() + except IOError, e: + print >> sys.stderr, e[1] + self.outstream.close() + while not queue.full(): + queue.put("") + + class JoinThread(WorkerThread): + def run(self): + for pipeline in self.instream: + #print >> sys.stderr, "wait" + passline = self.queue.get() + #print >> sys.stderr, "ok" + if pipeIsLeft: + self.outstream.write(pipeline) + self.outstream.write(passline) + else: + self.outstream.write(passline) + self.outstream.write(pipeline) + + pipe = Popen(cmd, shell=False,stdin=PIPE,stdout=PIPE) + queue = Queue(250) + t1 = SplitThread(queue, sys.stdin, pipe.stdin, pipeIsLeft) + t2 = JoinThread(queue, pipe.stdout, sys.stdout, pipeIsLeft) + t1.start() + t2.start() + t2.join() + ''; + spotifyCli = pkgs.writeBash "sp.sh" '' + # This is sp, the command-line Spotify controller. It talks to a running + # instance of the Spotify Linux client over dbus, providing an interface not + # unlike mpc. + # + # Put differently, it allows you to control Spotify without leaving the comfort + # of your command line, and without a custom client or Premium subscription. + # + # As an added bonus, it also works with ssh, at and cron. + # + # Example: + # $ sp weather girls raining men + # $ sp current + # Album 100 Hits Of The '80s + # Artist The Weather Girls + # Title It's Raining Men + # $ sp pause + # + # Alarm clock example: + # $ at 7:45 <<< 'sp bangarang' + # + # Remote example: + # $ ssh vader@prod02.nomoon.ta 'sp imperial march' + # + # + # Copyright (C) 2013 Wander Nauta + # + # Permission is hereby granted, free of charge, to any person obtaining a copy + # of this software, to deal in the Software without restriction, including + # without limitation the rights to use, copy, modify, merge, publish, + # distribute, sublicense, and/or sell copies of the Software, and to permit + # persons to whom the Software is furnished to do so, subject to the following + # conditions: + # + # The above copyright notice and this permission notice shall be included in + # all copies or substantial portions of the Software. + # + # The software is provided "as is", without warranty of any kind, express or + # implied, including but not limited to the warranties of merchantability, + # fitness for a particular purpose and noninfringement. In no event shall the + # authors or copyright holders be liable for any claim, damages or other + # liability, whether in an action of contract, tort or otherwise, arising from, + # out of or in connection with the software or the use or other dealings in the + # software. + # + + # CONSTANTS + + SP_VERSION="0.1" + SP_DEST="org.mpris.MediaPlayer2.spotify" + SP_PATH="/org/mpris/MediaPlayer2" + SP_MEMB="org.mpris.MediaPlayer2.Player" + + # SHELL OPTIONS + + shopt -s expand_aliases + + # UTILITY FUNCTIONS + + function require { + hash $1 2>/dev/null || { + echo >&2 "Error: '$1' is required, but was not found."; exit 1; + } + } + + # COMMON REQUIRED BINARIES + + # We need dbus-send to talk to Spotify. + require dbus-send + + # Assert standard Unix utilities are available. + require grep + require sed + require cut + require tr + + # 'SPECIAL' (NON-DBUS-ALIAS) COMMANDS + + function sp-dbus { + # Sends the given method to Spotify over dbus. + dbus-send --print-reply --dest=$SP_DEST $SP_PATH $SP_MEMB.$1 ''${*:2} > /dev/null + } + + function sp-open { + # Opens the given spotify: URI in Spotify. + sp-dbus OpenUri string:$1 + } + + function sp-metadata { + # Prints the currently playing track in a parseable format. + + dbus-send \ + --print-reply `# We need the reply.` \ + --dest=$SP_DEST \ + $SP_PATH \ + org.freedesktop.DBus.Properties.Get \ + string:"$SP_MEMB" string:'Metadata' \ + | grep -Ev "^method" `# Ignore the first line.` \ + | grep -Eo '("(.*)")|(\b[0-9][a-zA-Z0-9.]*\b)' `# Filter interesting fiels.`\ + | sed -E '2~2 a|' `# Mark odd fields.` \ + | tr -d '\n' `# Remove all newlines.` \ + | sed -E 's/\|/\n/g' `# Restore newlines.` \ + | sed -E 's/(xesam:)|(mpris:)//' `# Remove ns prefixes.` \ + | sed -E 's/^"//' `# Strip leading...` \ + | sed -E 's/"$//' `# ...and trailing quotes.` \ + | sed -E 's/"+/|/' `# Regard "" as seperator.` \ + | sed -E 's/ +/ /g' `# Merge consecutive spaces.` + } + + function sp-current { + # Prints the currently playing track in a friendly format. + require column + + sp-metadata \ + | grep --color=never -E "(title)|(album)|(artist)" \ + | sed 's/^\(.\)/\U\1/' \ + | column -t -s'|' + } + + function sp-eval { + # Prints the currently playing track as shell variables, ready to be eval'ed + require sort + + sp-metadata \ + | grep --color=never -E "(title)|(album)|(artist)|(trackid)|(trackNumber)" \ + | sort -r \ + | sed 's/^\([^|]*\)\|/\U\1/' \ + | sed -E 's/\|/="/' \ + | sed -E 's/$/"/' \ + | sed -E 's/^/SPOTIFY_/' + } + + function sp-art { + # Prints the artUrl. + + sp-metadata | grep "artUrl" | cut -d'|' -f2 + } + + function sp-display { + # Calls display on the artUrl. + + require display + display $(sp-art) + } + + function sp-feh { + # Calls feh on the artURl. + + require feh + feh $(sp-art) + } + + function sp-url { + # Prints the HTTP url. + + TRACK=$(sp-metadata | grep "url" | cut -d'|' -f2 | cut -d':' -f3) + echo "http://open.spotify.com/track/$TRACK" + } + + function sp-clip { + # Copies the HTTP url. + + require xclip + sp-url | xclip + } + + function sp-http { + # xdg-opens the HTTP url. + + require xdg-open + xdg-open $(sp-url) + } + + function sp-help { + # Prints usage information. + + echo "Usage: sp [command]" + echo "Control a running Spotify instance from the command line." + echo "" + echo " sp play - Play/pause Spotify" + echo " sp pause - Pause Spotify" + echo " sp next - Go to next track" + echo " sp prev - Go to previous track" + echo "" + echo " sp current - Format the currently playing track" + echo " sp metadata - Dump the current track's metadata" + echo " sp eval - Return the metadata as a shell script" + echo "" + echo " sp art - Print the URL to the current track's album artwork" + echo " sp display - Display the current album artwork with \`display\`" + echo " sp feh - Display the current album artwork with \`feh\`" + echo "" + echo " sp url - Print the HTTP URL for the currently playing track" + echo " sp clip - Copy the HTTP URL to the X clipboard" + echo " sp http - Open the HTTP URL in a web browser" + echo "" + echo " sp open - Open a spotify: uri" + echo " sp search - Start playing the best search result for the given query" + echo "" + echo " sp version - Show version information" + echo " sp help - Show this information" + echo "" + echo "Any other argument will start a search (i.e. 'sp foo' will search for foo)." + } + + function sp-search { + # Searches for tracks, plays the first result. + + require curl + + Q="$@" + SPTFY_URI=$( \ + curl -s -G --data-urlencode "q=$Q" ws.spotify.com/search/1/track \ + | grep -E -o "spotify:track:[a-zA-Z0-9]+" -m 1 \ + ) + + sp-open $SPTFY_URI + } + + function sp-version { + # Prints version information. + + echo "sp $SP_VERSION" + echo "Copyright (C) 2013 Wander Nauta" + echo "License MIT" + } + + # 'SIMPLE' (DBUS-ALIAS) COMMANDS + + alias sp-play=" sp-dbus PlayPause" + alias sp-pause=" sp-dbus Pause" + alias sp-next=" sp-dbus Next" + alias sp-prev=" sp-dbus Previous" + + # DISPATCHER + + # First, we connect to the dbus session spotify is on. This isn't really needed + # when running locally, but is crucial when we don't have an X display handy + # (for instance, when running sp over ssh.) + + SPOTIFY_PID="$(pidof -s spotify)" + + if [[ -z "$SPOTIFY_PID" ]]; then + echo "Error: Spotify is not running." + exit 1 + fi + + QUERY_ENVIRON="$(cat /proc/''${SPOTIFY_PID}/environ | tr '\0' '\n' | grep "DBUS_SESSION_BUS_ADDRESS" | cut -d "=" -f 2-)" + if [[ "''${QUERY_ENVIRON}" != "" ]]; then + export DBUS_SESSION_BUS_ADDRESS="''${QUERY_ENVIRON}" + fi + + # Then we dispatch the command. + + subcommand="$1" + + if [[ -z "$subcommand" ]]; then + # No arguments given, print help. + sp-help + else + # Arguments given, check if it's a command. + if $(type sp-$subcommand > /dev/null 2> /dev/null); then + # It is. Run it. + shift + eval "sp-$subcommand $@" + else + # It's not. Try a search. + eval "sp-search $@" + fi + fi + ''; + spotifyGenius = pkgs.writeBash "spgenius.sh" '' + function normalise { + echo ''${1// /-} + } + eval $(${spotifyCli} eval) + ${defaultApplications.webBrowser} "http://genius.com/$(normalise "$SPOTIFY_ARTIST")-$(normalise "$SPOTIFY_TITLE")-lyrics" + ''; +in { + compile = compile; + easy-backup = easyBackup; + colorize = colorize; + bing-wallpaper = bingWallpaper; + git-pull-all = gitPullAll; + hdef = haskellDefinition; + hfind = haskellFind; + hgrep = haskellGrep; + htags = haskellTags; + sp = spotifyCli; + spgenius = spotifyGenius; +} diff --git a/dot/stack.nix b/dot/stack.nix index 8320c59..c4fc889 100644 --- a/dot/stack.nix +++ b/dot/stack.nix @@ -1,10 +1,9 @@ -{ fullName, fullEmail, githubUser }: +user: '' templates: params: - author-name: ${fullName} - author-email: ${fullEmail} - category: Data - copyright: 'Copyright: (c) 2018 ${fullName}' - github-username: ${githubUser} + author-name: ${user.name} + author-email: ${user.email} + copyright: 'Copyright: (c) 2018 ${user.name}' + github-username: ${user.github} '' diff --git a/dot/terminal.nix b/dot/terminal.nix index 2e004c9..b8a807a 100644 --- a/dot/terminal.nix +++ b/dot/terminal.nix @@ -1,13 +1,13 @@ -{ defaultApplications }: +defaultApplications: with import ../theme.nix; '' [Configuration] -BackgroundDarkness=0.95 +BackgroundDarkness=0.9 BackgroundMode=TERMINAL_BACKGROUND_TRANSPARENT ColorBackground=${veryDark} -ColorCursor=${light} -ColorForeground=${light} -ColorPalette=${dark};${red.dark};${green.dark};${yellow.dark};${blue.dark};${magenta.dark};${cyan.dark};${light};${dark};${red.light};${green.light};${yellow.light};${blue.light};${magenta.light};${cyan.light};${light} +ColorCursor=${gray.light} +ColorForeground=${gray.light} +ColorPalette=${builtins.concatStringsSep ";" colorPalette} FontName=${terminalFont.regular.name} ${toString terminalFont.size} MiscAlwaysShowTabs=FALSE MiscBell=TRUE diff --git a/dot/tmux.nix b/dot/tmux.nix index bfd5102..3d93a2d 100644 --- a/dot/tmux.nix +++ b/dot/tmux.nix @@ -4,8 +4,7 @@ set -g status-left-length 32 set -g status-right-length 150 # Appearance -set -g default-terminal "screen-256color" -set -g status-utf8 on +# set -g status-utf8 on set -g status-bg default # set -g status-fg white setw -g window-status-format "#[fg=colour12,bg=colour233] #I #[fg=white,bg=colour237] #W " diff --git a/dot/vim.nix b/dot/vim.nix index 2db0114..602c3d7 100644 --- a/dot/vim.nix +++ b/dot/vim.nix @@ -1,153 +1,190 @@ -'' -filetype off - -" if exists("g:loaded_airline") -set noshowmode laststatus=0 noruler -let g:airline#extensions#tabline#close_symbol = 'X' -let g:airline#extensions#tabline#enabled = 0 -let g:airline#extensions#tabline#left_alt_sep = '' -let g:airline#extensions#tabline#left_sep = '' -let g:airline#extensions#tabline#right_alt_sep = '' -let g:airline#extensions#tabline#right_sep = '' -let g:airline#extensions#tabline#show_close_button = 1 -let g:airline#extensions#tabline#show_tab_type = 0 -let g:airline#extensions#tabline#tab_min_count = 2 -let g:airline#extensions#tabline#tab_nr_type = 0 -let g:airline#extensions#tmuxline#enabled = 0 -let g:airline#extensions#wordcount#enabled = 1 -let g:airline_left_alt_sep = '' -let g:airline_left_sep = '' -let g:airline_right_alt_sep = '' -let g:airline_right_sep = '' -let g:airline_section_z = '%{line(".")}/%{line("$")} %{col(".")}' -" endif -" if exists("g:loaded_airline_themes") -let g:airline_theme='simple' -" endif - -" if exists("g:loaded_syntastic_plugin") -let g:syntastic_always_populate_loc_list = 1 -let g:syntastic_auto_loc_list = 0 -let g:syntastic_check_on_open = 0 -let g:syntastic_check_on_wq = 0 -map ,s :SyntasticToggleMode -" endif - -" if exists("g:loaded_gundo") -nnoremap :GundoToggle -" endif - -" if supertab -let g:SuperTabDefaultCompletionType = '' -if has("unix") - inoremap =SuperTabAlternateCompletion("\c-x>\c-o>") -endif - -" if tabular -vmap a= :Tabularize /= -vmap a; :Tabularize /:: -vmap a- :Tabularize /-> - -colorscheme delek - -set path=$PWD/** -set completeopt=menu,longest -set wildmode=longest,list,full -set shortmess+=aI -set nowritebackup noswapfile -set mouse=a -set showmatch -set encoding=utf8 -set ffs=unix,dos,mac -set smartindent -set nowrap -set nohlsearch -set clipboard=unnamedplus,autoselect -set nopaste -set list listchars=tab:▸\ ,extends:❯,precedes:❮,nbsp:⍽ showbreak=↪ -set foldlevelstart=30 - -" if exists("g:loaded_netrwPlugin") -let g:netrw_banner=0 -let g:netrw_browse_split=4 -let g:netrw_altv=1 " open splits to the right -let g:netrw_liststyle=3 " tree view -let g:netrw_list_hide=netrw_gitignore#Hide() -let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+' -" endif - -call matchadd('colorcolumn', '\%101v', 100) -highlight folded ctermbg=black -highlight colorcolumn ctermbg=red -highlight matchparen cterm=bold ctermbg=black ctermfg=white -highlight TrailSpace ctermbg=red guibg=darkred -match TrailSpace /\s\+$/ - -" undofile - This allows you to use undos after exiting and restarting -" This, like swap and backups, uses .vim-undo first, then ~/.vim/undo -" :help undo-persistence -if exists("+undofile") - if isdirectory($HOME . '/.vim/undo') == 0 - :silent !mkdir -p ~/.vim/undo > /dev/null 2>&1 +pkgs: +let vimrc = with import ../constants.nix; '' + if exists("g:loaded_airline") + set noshowmode laststatus=0 noruler + let g:airline#extensions#tabline#close_symbol = 'X' + let g:airline#extensions#tabline#enabled = 0 + let g:airline#extensions#tabline#left_alt_sep = '' + let g:airline#extensions#tabline#left_sep = '' + let g:airline#extensions#tabline#right_alt_sep = '' + let g:airline#extensions#tabline#right_sep = '' + let g:airline#extensions#tabline#show_close_button = 1 + let g:airline#extensions#tabline#show_tab_type = 0 + let g:airline#extensions#tabline#tab_min_count = 2 + let g:airline#extensions#tabline#tab_nr_type = 0 + let g:airline#extensions#tmuxline#enabled = 0 + let g:airline#extensions#wordcount#enabled = 1 + let g:airline_left_alt_sep = '' + let g:airline_left_sep = '' + let g:airline_right_alt_sep = '' + let g:airline_right_sep = '' + let g:airline_section_z = '%{line(".")}/%{line("$")} %{col(".")}' + endif + if exists("g:loaded_airline_themes") + let g:airline_theme='simple' endif - set undodir=./.vim-undo// - set undodir+=~/.vim/undo// - set undofile -endif -nmap ddp -nmap ddkP -vmap xp`[V`] -vmap xkP`[V`] + if exists("g:loaded_syntastic_plugin") + let g:syntastic_always_populate_loc_list = 1 + let g:syntastic_auto_loc_list = 0 + let g:syntastic_check_on_open = 0 + let g:syntastic_check_on_wq = 0 + map ,s :SyntasticToggleMode + endif -nnoremap @=(foldlevel('.')?'za':"\") -vnoremap zf + if exists("g:loaded_gundo") + nnoremap :GundoToggle + endif -command! RandomLine execute 'normal! '.(system('/bin/bash -c "echo -n $RANDOM"') % line('$')).'G' + " if tabular + vmap a= :Tabularize /= + vmap a; :Tabularize /:: + vmap a- :Tabularize /-> -function! StripTrailingWhitespaces() - let _s=@/ - let l=line(".") - let c=col(".") + colorscheme delek + set t_Co=256 - %s/\s\+$//e + filetype plugin indent on + set nocompatible + set smartcase + set shiftwidth=2 tabstop=2 expandtab + set number + set path=$PWD/** + set completeopt=menu,longest + set wildmode=longest,list,full + set wildignore+=${commaSep ignoredFiles} + set shortmess+=aI + set nowritebackup noswapfile + set mouse=a + set showmatch + set encoding=utf8 + set ffs=unix,dos,mac + set smartindent + set nowrap + set nohlsearch + set clipboard=unnamedplus,autoselect + set nopaste + set list listchars=tab:▸\ ,extends:❯,precedes:❮,nbsp:⍽ showbreak=↪ + set foldlevelstart=30 - let @/=_s - call cursor(l,c) -endfunction + if exists("g:loaded_netrwPlugin") + let g:netrw_banner=0 + let g:netrw_browse_split=4 + let g:netrw_altv=1 " open splits to the right + let g:netrw_liststyle=3 " tree view + let g:netrw_list_hide=netrw_gitignore#Hide() + let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+' + endif -function! s:DiffWithSaved() - let filetype=&ft - diffthis - vnew | r # | normal! 1Gdd - diffthis - execute "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype -endfunction -command! DiffSaved call s:DiffWithSaved() + call matchadd('colorcolumn', '\%101v', 100) + highlight folded ctermbg=black + highlight colorcolumn ctermbg=red + highlight matchparen cterm=bold ctermbg=black ctermfg=white + highlight TrailSpace ctermbg=red guibg=darkred + match TrailSpace /\s\+$/ -if has("autocmd") - autocmd filetype markdown,text set formatprg=par\ -w80 - autocmd filetype haskell set formatprg=hindent - autocmd filetype markdown,text set textwidth=80 - autocmd filetype markdown,text set formatoptions+=t - autocmd bufreadpost * - \ if line("'\"") > 0 && line("'\"") <= line("$") | - \ exe "normal! g`\"" | - \ endif - autocmd bufwritepre * :call StripTrailingWhitespaces() - autocmd bufnewfile,bufread *.md set filetype=markdown.pandoc - autocmd bufnewfile,bufread *.asm set filetype=nasm - autocmd bufnewfile,bufread *.bf set filetype=brainfuck - autocmd bufnewfile,bufread *.do set filetype=sh - autocmd bufnewfile,bufread config set filetype=conf - autocmd bufnewfile,bufread *.conf set filetype=conf - autocmd bufnewfile,bufread *.4th set filetype=forth - autocmd bufnewfile,bufread *.c set keywordprg=man\ 3 - autocmd bufnewfile,bufread *.h set keywordprg=man\ 3 + " undofile - This allows you to use undos after exiting and restarting + " This, like swap and backups, uses .vim-undo first, then ~/.vim/undo + " :help undo-persistence + if exists("+undofile") + if isdirectory($HOME . '/.vim/undo') == 0 + :silent !mkdir -p ~/.vim/undo > /dev/null 2>&1 + endif + set undodir=./.vim-undo// + set undodir+=~/.vim/undo// + set undofile + endif - autocmd filetype make setlocal noexpandtab + nmap ddp | vmap xp`[V`] + nmap ddkP | vmap xkP`[V`] - autocmd bufreadpre * setlocal foldmethod=indent - autocmd bufwinenter * if &fdm == 'indent' | setlocal foldmethod=manual | endif -endif -'' + nnoremap @=(foldlevel('.')?'za':"\") + vnoremap zf + + command! RandomLine execute 'normal! '.(system('/bin/bash -c "echo -n $RANDOM"') % line('$')).'G' + + function! StripTrailingWhitespaces() + let _s=@/ + let l=line(".") + let c=col(".") + + %s/\s\+$//e + + let @/=_s + call cursor(l,c) + endfunction + + function! s:DiffWithSaved() + let filetype=&ft + diffthis + vnew | r # | normal! 1Gdd + diffthis + execute "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype + endfunction + command! DiffSaved call s:DiffWithSaved() + + if has("autocmd") + autocmd filetype markdown,text set formatprg=par\ -w80 + autocmd filetype haskell set formatprg=hindent + autocmd filetype markdown,text set textwidth=80 + autocmd filetype markdown,text set formatoptions+=t + autocmd bufreadpost * + \ if line("'\"") > 0 && line("'\"") <= line("$") | + \ exe "normal! g`\"" | + \ endif + autocmd bufwritepre * :call StripTrailingWhitespaces() + autocmd bufnewfile,bufread *.md set filetype=markdown.pandoc + autocmd bufnewfile,bufread *.asm set filetype=nasm + autocmd bufnewfile,bufread *.tex :packadd vimtex | set filetype=tex + autocmd bufnewfile,bufread *.rust :packadd rust-vim deoplete-rust + autocmd bufnewfile,bufread *.nix :packadd vim-nix + autocmd filetype javascript *.js :packadd vim-javascript + autocmd bufnewfile,bufread *.ts :packadd vim-typescript + autocmd filetype haskell :packadd Hoogle + autocmd bufnewfile,bufread *.do set filetype=sh + autocmd bufnewfile,bufread config set filetype=conf + autocmd bufnewfile,bufread *.conf set filetype=conf + autocmd bufnewfile,bufread *.4th set filetype=forth + autocmd bufnewfile,bufread *.c set keywordprg=man\ 3 + autocmd bufnewfile,bufread *.h set keywordprg=man\ 3 + + autocmd filetype make setlocal noexpandtab + + autocmd bufreadpre * setlocal foldmethod=indent + autocmd bufwinenter * if &fdm == 'indent' | setlocal foldmethod=manual | endif + endif + ''; in +pkgs.vim_configurable.customize { + name = "vim"; + vimrcConfig.customRC = vimrc; + vimrcConfig.packages.vim = with pkgs.vimPlugins; { + start = [ + ctrlp + deoplete-nvim + supertab + syntastic + tabular + vim-airline + vim-airline-themes + vim-commentary + vim-eunuch + vim-fugitive + vim-gitgutter + vim-pandoc vim-pandoc-after vim-pandoc-syntax + vim-repeat + vim-sensible + vim-startify + vim-surround + ]; + opt = [ + Hoogle + deoplete-rust + idris-vim + vimtex + rust-vim + typescript-vim + vim-javascript + vim-nix + ]; + }; +} diff --git a/theme.nix b/theme.nix index 541ee03..b822de7 100644 --- a/theme.nix +++ b/theme.nix @@ -10,16 +10,20 @@ white = "#ffffff"; black = "#000000"; - gray = { light = "#aaaaaa"; dark = "#888888"; }; - - # Antares color scheme - dark = "#151515"; veryDark = "#080808"; - red = { light = "#de575c"; dark = "#de575c"; }; - yellow = { light = "#ebe971"; dark = "#ebe971"; }; - green = { light = "#00b853"; dark = "#00b853"; }; - blue = { light = "#90d0f0"; dark = "#7fc6f0"; }; - magenta = { light = "#cf9ffa"; dark = "#cf9ffa"; }; - cyan = { light = "#4ae5e8"; dark = "#4ae5e8"; }; - light = "#bbbbbb"; -} +} // rec { + colorPalette = [ + gray.dark red.dark green.dark yellow.dark blue.dark magenta.dark cyan.dark gray.light + gray.dark red.light green.light yellow.light blue.light magenta.light cyan.light gray.light + ]; + + # Antares color scheme + gray = { light = "#bbbbbb"; dark = "#151515"; }; + red = { light = "#de575c"; dark = "#de575c"; }; + yellow = { light = "#ebe971"; dark = "#ebe971"; }; + green = { light = "#00b853"; dark = "#00b853"; }; + blue = { light = "#90d0f0"; dark = "#7fc6f0"; }; + magenta = { light = "#cf9ffa"; dark = "#cf9ffa"; }; + cyan = { light = "#4ae5e8"; dark = "#4ae5e8"; }; + } +