From a6e427451e4759b066f6a1a068b9c4f417dc1bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Tue, 8 Jan 2019 16:57:31 +0100 Subject: [PATCH] Split up configuration --- config/dunstrc.nix | 162 ++ config/xsession.nix | 61 + {secret => config/zsh}/ntfy.yml | 1 + .../powerlevel9k/.github/ISSUE_TEMPLATE.md | 35 + .../.github/PULL_REQUEST_TEMPLATE.md | 32 + .../oh-my-zsh-custom/powerlevel9k/.gitignore | 3 + .../oh-my-zsh-custom/powerlevel9k/.gitmodules | 3 + .../oh-my-zsh-custom/powerlevel9k/.travis.yml | 77 + .../powerlevel9k/CHANGELOG.md | 450 ++++ .../powerlevel9k/CODE_OF_CONDUCT.md | 46 + .../zsh/oh-my-zsh-custom/powerlevel9k/LICENSE | 20 + .../oh-my-zsh-custom/powerlevel9k/README.md | 765 +++++++ .../oh-my-zsh-custom/powerlevel9k/TESTS.md | 69 + .../powerlevel9k/debug/font-issues.zsh | 423 ++++ .../powerlevel9k/debug/iterm.zsh | 86 + .../powerlevel9k/docker/antibody/Dockerfile | 8 + .../powerlevel9k/docker/antibody/install.zsh | 1 + .../powerlevel9k/docker/antibody/zshrc | 2 + .../powerlevel9k/docker/antigen/Dockerfile | 8 + .../powerlevel9k/docker/antigen/install.zsh | 12 + .../powerlevel9k/docker/antigen/zshrc | 4 + .../docker/base-4.3.11/Dockerfile | 31 + .../powerlevel9k/docker/base-5.0.3/Dockerfile | 33 + .../powerlevel9k/docker/base-5.1.1/Dockerfile | 35 + .../powerlevel9k/docker/base-5.2/Dockerfile | 35 + .../powerlevel9k/docker/base-5.3.1/Dockerfile | 40 + .../powerlevel9k/docker/base-5.4.2/Dockerfile | 35 + .../powerlevel9k/docker/base-5.5.1/Dockerfile | 35 + .../powerlevel9k/docker/dotfile/Dockerfile | 5 + .../powerlevel9k/docker/dotfile/zshrc | 1 + .../powerlevel9k/docker/fred-sudoers | 2 + .../powerlevel9k/docker/omz/Dockerfile | 8 + .../powerlevel9k/docker/omz/install.zsh | 4 + .../powerlevel9k/docker/omz/zshrc | 5 + .../powerlevel9k/docker/prezto/Dockerfile | 7 + .../powerlevel9k/docker/prezto/install.zsh | 18 + .../powerlevel9k/docker/zgen/Dockerfile | 8 + .../powerlevel9k/docker/zgen/install.zsh | 5 + .../powerlevel9k/docker/zgen/zshrc | 10 + .../powerlevel9k/docker/zim/Dockerfile | 7 + .../powerlevel9k/docker/zim/install.zsh | 21 + .../powerlevel9k/docker/zplug/Dockerfile | 8 + .../powerlevel9k/docker/zplug/install.zsh | 5 + .../powerlevel9k/docker/zplug/zshrc | 5 + .../powerlevel9k/docker/zplugin/Dockerfile | 8 + .../powerlevel9k/docker/zplugin/install.zsh | 12 + .../powerlevel9k/docker/zplugin/zshrc.plugins | 5 + .../powerlevel9k/docker/zpm/Dockerfile | 8 + .../powerlevel9k/docker/zpm/install.zsh | 6 + .../powerlevel9k/docker/zpm/zshrc | 3 + .../powerlevel9k/docker/zshing/Dockerfile | 7 + .../powerlevel9k/docker/zshing/install.zsh | 16 + .../powerlevel9k/docker/zulu/Dockerfile | 7 + .../powerlevel9k/docker/zulu/install.zsh | 10 + .../powerlevel9k/functions/colors.zsh | 358 +++ .../powerlevel9k/functions/icons.zsh | 560 +++++ .../powerlevel9k/functions/utilities.zsh | 373 ++++ .../powerlevel9k/functions/vcs.zsh | 177 ++ .../powerlevel9k/powerlevel9k.zsh-theme | 1955 +++++++++++++++++ .../powerlevel9k/prompt_powerlevel9k_setup | 1 + .../powerlevel9k/test-bsd-vm/Vagrantfile | 87 + .../test-bsd-vm/bootstrap-zero.sh | 3 + .../powerlevel9k/test-bsd-vm/bootstrap.sh | 13 + .../powerlevel9k/test-in-docker | 200 ++ .../powerlevel9k/test-vm-providers/plain.sh | 9 + .../test-vm-providers/setup-environment.sh | 44 + .../powerlevel9k/test-vm/README.md | 25 + .../powerlevel9k/test-vm/Vagrantfile | 82 + .../powerlevel9k/test-vm/antigen.sh | 30 + .../powerlevel9k/test-vm/bootstrap.sh | 19 + .../powerlevel9k/test-vm/omz.sh | 33 + .../powerlevel9k/test-vm/prezto.sh | 29 + .../test/core/color_overriding.spec | 62 + .../test/core/joining_segments.spec | 187 ++ .../powerlevel9k/test/core/prompt.spec | 104 + .../test/core/visual_identifier.spec | 60 + .../powerlevel9k/test/functions/colors.spec | 67 + .../powerlevel9k/test/functions/icons.spec | 473 ++++ .../test/functions/utilities.spec | 109 + .../powerlevel9k/test/powerlevel9k.spec | 123 ++ .../powerlevel9k/test/segments/anaconda.spec | 69 + .../test/segments/aws_eb_env.spec | 61 + .../test/segments/background_jobs.spec | 78 + .../powerlevel9k/test/segments/battery.spec | 177 ++ .../test/segments/command_execution_time.spec | 104 + .../powerlevel9k/test/segments/context.spec | 131 ++ .../powerlevel9k/test/segments/custom.spec | 86 + .../test/segments/detect_virt.spec | 83 + .../powerlevel9k/test/segments/dir.spec | 771 +++++++ .../test/segments/disk_usage.spec | 131 ++ .../test/segments/go_version.spec | 88 + .../powerlevel9k/test/segments/ip.spec | 231 ++ .../test/segments/kubecontext.spec | 104 + .../test/segments/laravel_version.spec | 72 + .../powerlevel9k/test/segments/load.spec | 149 ++ .../test/segments/node_version.spec | 41 + .../powerlevel9k/test/segments/nodeenv.spec | 99 + .../powerlevel9k/test/segments/nvm.spec | 72 + .../test/segments/php_version.spec | 42 + .../powerlevel9k/test/segments/public_ip.spec | 222 ++ .../powerlevel9k/test/segments/ram.spec | 66 + .../test/segments/rust_version.spec | 51 + .../powerlevel9k/test/segments/ssh.spec | 80 + .../powerlevel9k/test/segments/status.spec | 113 + .../powerlevel9k/test/segments/swap.spec | 58 + .../test/segments/swift_version.spec | 57 + .../test/segments/symfony_version.spec | 117 + .../powerlevel9k/test/segments/todo.spec | 58 + .../powerlevel9k/test/segments/vcs-git.spec | 493 +++++ .../powerlevel9k/test/segments/vcs-hg.spec | 207 ++ .../powerlevel9k/test/segments/vi_mode.spec | 48 + .../powerlevel9k/test/suite.spec | 17 + config/zsh/zsh.nix | 60 + dunstrc | 373 ---- home.nix | 111 +- ntfy.yml.example | 7 - zsh/oh-my-zsh-custom/powerlevel9k | 1 - 117 files changed, 12134 insertions(+), 490 deletions(-) create mode 100644 config/dunstrc.nix create mode 100644 config/xsession.nix rename {secret => config/zsh}/ntfy.yml (91%) create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/.github/ISSUE_TEMPLATE.md create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/.github/PULL_REQUEST_TEMPLATE.md create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/.gitignore create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/.gitmodules create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/.travis.yml create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/CHANGELOG.md create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/CODE_OF_CONDUCT.md create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/LICENSE create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/README.md create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/TESTS.md create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/debug/font-issues.zsh create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/debug/iterm.zsh create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antibody/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antibody/install.zsh create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antibody/zshrc create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antigen/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antigen/install.zsh create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antigen/zshrc create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-4.3.11/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.0.3/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.1.1/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.2/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.3.1/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.4.2/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.5.1/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/dotfile/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/dotfile/zshrc create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/fred-sudoers create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/omz/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/omz/install.zsh create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/omz/zshrc create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/prezto/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/prezto/install.zsh create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zgen/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zgen/install.zsh create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zgen/zshrc create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zim/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zim/install.zsh create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplug/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplug/install.zsh create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplug/zshrc create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplugin/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplugin/install.zsh create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplugin/zshrc.plugins create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zpm/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zpm/install.zsh create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zpm/zshrc create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zshing/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zshing/install.zsh create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zulu/Dockerfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zulu/install.zsh create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/functions/colors.zsh create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/functions/icons.zsh create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/functions/utilities.zsh create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/functions/vcs.zsh create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/powerlevel9k.zsh-theme create mode 120000 config/zsh/oh-my-zsh-custom/powerlevel9k/prompt_powerlevel9k_setup create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/test-bsd-vm/Vagrantfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/test-bsd-vm/bootstrap-zero.sh create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/test-bsd-vm/bootstrap.sh create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test-in-docker create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm-providers/plain.sh create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm-providers/setup-environment.sh create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/README.md create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/Vagrantfile create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/antigen.sh create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/bootstrap.sh create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/omz.sh create mode 100644 config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/prezto.sh create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/core/color_overriding.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/core/joining_segments.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/core/prompt.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/core/visual_identifier.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/functions/colors.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/functions/icons.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/functions/utilities.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/powerlevel9k.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/anaconda.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/aws_eb_env.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/background_jobs.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/battery.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/command_execution_time.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/context.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/custom.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/detect_virt.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/dir.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/disk_usage.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/go_version.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/ip.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/kubecontext.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/laravel_version.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/load.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/node_version.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/nodeenv.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/nvm.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/php_version.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/public_ip.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/ram.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/rust_version.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/ssh.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/status.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/swap.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/swift_version.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/symfony_version.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/todo.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/vcs-git.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/vcs-hg.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/vi_mode.spec create mode 100755 config/zsh/oh-my-zsh-custom/powerlevel9k/test/suite.spec create mode 100644 config/zsh/zsh.nix delete mode 100644 dunstrc delete mode 100644 ntfy.yml.example delete mode 160000 zsh/oh-my-zsh-custom/powerlevel9k diff --git a/config/dunstrc.nix b/config/dunstrc.nix new file mode 100644 index 0000000..ece951b --- /dev/null +++ b/config/dunstrc.nix @@ -0,0 +1,162 @@ +{pkgs, config, lib, ...}: +{ + +home.file.dunst = { + target = ".config/dunst/dunstrc"; + + text = '' +[global] + monitor = 0 + follow = keyboard + geometry = "350x5-0+24" + indicate_hidden = yes + shrink = yes + transparency = 20 + notification_height = 0 + separator_height = 2 + padding = 0 + horizontal_padding = 8 + frame_width = 3 + frame_color = "#282828" + + # Define a color for the separator. + # possible values are: + # * auto: dunst tries to find a color fitting to the background; + # * foreground: use the same color as the foreground; + # * frame: use the same color as the frame; + # * anything else will be interpreted as a X color. + separator_color = frame + + # Sort messages by urgency. + sort = yes + + idle_threshold = 120 + font = Monospace 12 + line_height = 0 + markup = full + + # The format of the message. Possible variables are: + # %a appname + # %s summary + # %b body + # %i iconname (including its path) + # %I iconname (without its path) + # %p progress value if set ([ 0%] to [100%]) or nothing + # %n progress value if set without any extra characters + # %% Literal % + # Markup is allowed + format = "%s\n%b" + + alignment = left + show_age_threshold = 60 + word_wrap = yes + ellipsize = middle + ignore_newline = no + stack_duplicates = true + hide_duplicate_count = true + show_indicators = yes + icon_position = left + max_icon_size = 40 + #icon_path = /usr/share/icons/gnome/16x16/status/:/usr/share/icons/gnome/16x16/devices/:/usr/share/icons/Adwaita/256x256/status/ + sticky_history = yes + history_length = 20 + dmenu = ${pkgs.dmenu}/bin/dmenu -p dunst: + browser = ${pkgs.firefox}/bin/firefox -new-tab + + # Always run rule-defined scripts, even if the notification is suppressed + always_run_script = true + + title = Dunst + class = Dunst + startup_notification = false + force_xinerama = false +[experimental] + per_monitor_dpi = false + +[shortcuts] + close = ctrl+space + close_all = ctrl+shift+space + history = ctrl+grave + context = ctrl+shift+period + +[urgency_low] + # IMPORTANT: colors have to be defined in quotation marks. + # Otherwise the "#" and following would be interpreted as a comment. + background = "#282828" + foreground = "#928374" + timeout = 5 + # Icon for notifications with low urgency, uncomment to enable + #icon = /path/to/icon + +[urgency_normal] + background = "#458588" + foreground = "#ebdbb2" + timeout = 5 + +[urgency_critical] + background = "#cc2421" + foreground = "#ebdbb2" + frame_color = "#fabd2f" + timeout = 0 + +# Every section that isn't one of the above is interpreted as a rules to +# override settings for certain messages. +# Messages can be matched by "appname", "summary", "body", "icon", "category", +# "msg_urgency" and you can override the "timeout", "urgency", "foreground", +# "background", "new_icon" and "format". +# Shell-like globbing will get expanded. +# +# SCRIPTING +# You can specify a script that gets run when the rule matches by +# setting the "script" option. +# The script will be called as follows: +# script appname summary body icon urgency +# where urgency can be "LOW", "NORMAL" or "CRITICAL". +# +# NOTE: if you don't want a notification to be displayed, set the format +# to "". +# NOTE: It might be helpful to run dunst -print in a terminal in order +# to find fitting options for rules. + +#[espeak] +# summary = "*" +# script = dunst_espeak.sh + +#[script-test] +# summary = "*script*" +# script = dunst_test.sh + +#[ignore] +# # This notification will not be displayed +# summary = "foobar" +# format = "" + +#[history-ignore] +# # This notification will not be saved in history +# summary = "foobar" +# history_ignore = yes + +#[signed_on] +# appname = Pidgin +# summary = "*signed on*" +# urgency = low +# +#[signed_off] +# appname = Pidgin +# summary = *signed off* +# urgency = low +# +#[says] +# appname = Pidgin +# summary = *says* +# urgency = critical +# +#[twitter] +# appname = Pidgin +# summary = *twitter.com* +# urgency = normal +# +# vim: ft=cfg + ''; + }; +} diff --git a/config/xsession.nix b/config/xsession.nix new file mode 100644 index 0000000..8ad09c5 --- /dev/null +++ b/config/xsession.nix @@ -0,0 +1,61 @@ +{pkgs, config, lib, ...}: +{ + home.keyboard = { + layout = "no-latin1"; + }; + + xsession = { + enable = true; + windowManager = { + i3.enable = true; + i3.config = { + modifier = "Mod4"; + keybindings = let modifier = "Mod4"; #xsession.windowManager.i3.config.modifier; + in lib.mkOptionDefault { + "${modifier}+0" = "workspace 10"; + "${modifier}+Shift+0" = "move container to workspace 10"; + + "${modifier}+Tab" = "workspace next"; + "${modifier}+Shift+Tab" = "workspace prev"; + + "XF86AudioRaiseVolume" = "exec --no-startup-id pactl set-sink-volume 0 +5%"; + "XF86AudioLowerVolume" = "exec --no-startup-id pactl set-sink-volume 0 -5%"; + "XF86AudioMute" = "exec --no-startup-id pactl set-sink-mute 0 toggle"; + "XF86AudioMicMute" = "exec --no-startup-id pactl set-source-mute 1 toggle"; + + "XF86MonBrightnessUp" = "exec --no-startup-id xbacklight -inc 5"; + "XF86MonBrightnessDown" = "exec --no-startup-id xbacklight -dec 5"; + + "XF86Display" = "exec arandr"; + + "Print" = "exec scrot %Y-%m-%d_$wx$h_scrot.png -z -e 'mv $f /home/daniel/Pictures/screenshots/'"; + "${modifier}+Print" = "exec scrot /home/daniel/Pictures/Screenshots/%Y-%m-%d_$wx$h_scrot.png -z"; + + + "${modifier}+n" = "exec dolphin"; + "${modifier}+b" = "exec firefox"; + "${modifier}+t" = "exec gedit"; + + "${modifier}+Return" = lib.mkForce "exec i3-sensible-terminal"; + "${modifier}+Shift+Return" = "exec i3-sensible-terminal -e ssh daniel@adam"; + }; + }; + }; + }; + + services.compton = { + enable = true; + backend = "xrender"; + }; + + home.packages = [ + pkgs.dunst + pkgs.libnotify + + pkgs.dmenu + ]; +} + + + + diff --git a/secret/ntfy.yml b/config/zsh/ntfy.yml similarity index 91% rename from secret/ntfy.yml rename to config/zsh/ntfy.yml index 0fcf634..3700dd9 100644 --- a/secret/ntfy.yml +++ b/config/zsh/ntfy.yml @@ -1,6 +1,7 @@ --- backends: - matrix + - linux matrix: url: "https://matrix.dodsorf.as" roomId: "***REMOVED***" diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/.github/ISSUE_TEMPLATE.md b/config/zsh/oh-my-zsh-custom/powerlevel9k/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..01fbc41 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,35 @@ +Thanks for opening an issue! For a project that deals with as many different things as P9k, debugging problems can be difficult. Please follow the guide, below, to create a bug report that will help us help you! + +### Before Opening a Bug +P9k is lovingly maintained by volunteers, and we are happy to help you! You can help us by first making sure your issue hasn't already been solved before opening a new one. Please check the [Troubleshooting Guide](https://github.com/bhilburn/powerlevel9k/wiki/Troubleshooting) first. Many issues are actually local configuration problems, which may have previously been solved by another user - be sure to also [search the existing issues](https://github.com/bhilburn/powerlevel9k/issues?utf8=%E2%9C%93&q=is%3Aissue) before opening a new one. + +Once you've done these things, you can delete this section and proceed `=)` + +----- + +#### Describe Your Issue +What is happening? + +Most issues are best explained with a screenshot. Please share one if you can! + +#### Have you tried to debug or fix it? + + +Have you tinkered with your settings, and what happened when you did? Did you find a bit of code that you think might be the culprit? Let us know what you've done so far! + +#### Environment Information +This information will help us understand your configuration. + + - What version of ZSH are you using? You can use `zsh --version` to see this. + - Do you use a ZSH framework (e.g., Oh-My-ZSH, Antigen)? + - How did you install P9k (cloning the repo, by tarball, a package from your OS, etc.,)? + - What version of P9k are you using? + - Which terminal emulator do you use? + +#### Issues with Fonts & Icons +You may delete this section if your issue is not font / icon related. + + - Which font do you use? + - Which [font configuration mode](https://github.com/bhilburn/powerlevel9k/wiki/About-Fonts) are you using? You can check this with (`echo $POWERLEVEL9K_MODE`). + - Please share the contents of `$P9k/debug/font-issues.zsh`. + - If this is an icon problem, does the output of `$ get_icon_names` look correct? diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/.github/PULL_REQUEST_TEMPLATE.md b/config/zsh/oh-my-zsh-custom/powerlevel9k/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..4ade805 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,32 @@ +Thank you so much for opening a PR for P9k! Many of our best features and segments have come from the community, and we are excited to see your contribution. + +To help you make the best PR, here are some guidelines: + + - The `master` branch is our *stable* branch, and the `next` branch is our development branch. If you are submitting a bug fix, please file your PR against `master`. If it is a new feature, enhancement, segment, or something similar, please submit it against `next`. For more information, please see our [Developer's Guide](https://github.com/bhilburn/powerlevel9k/wiki/Developer's-Guide). + - We maintain unit tests for segments and features in the `test` directory. Please add unit tests for anything new you have developed! If you aren't sure how to do this, go ahead and file your PR and ask for help! + - For running manual tests in different environments, we have Vagrant and Docker configurations. Please see the [Test README](https://github.com/bhilburn/powerlevel9k/blob/next/TESTS.md) and make sure your new feature is working as expected! + - If your PR requires user configuration, please make sure that it includes an update to the README describing this. + - P9k maintains a lot of useful information in our [Wiki](https://github.com/bhilburn/powerlevel9k/wiki). Depending on the content of your PR, we might ask you to update the Wiki (or provide text for us to use) to document your work. Most PRs don't require this. + - Please make your commit messages useful! Here is a [great short guide on useful commit messages](https://code.likeagirl.io/useful-tips-for-writing-better-git-commit-messages-808770609503). + +Once you have submitted your PR, P9k core contributors will review the code and work with you to get it merged. During this process, we might request changes to your code and discuss different ways of doing things. This is all part of the open source process, and our goal is to help you create the best contribution possible for P9k `=)`. + +Please follow this template for creating your PR: + +#### Title +Please make the title of your PR descriptive! If appropriate, please prefix the title with one of these tags: + + - [Bugfix] + - [New Segment] + - [Docs] + - [Enhancement] + +#### Description +Please describe the contribution your PR makes! Screenshots are especially helpful, here, if it's a new segment. + +If your PR is addressing an issue, please reference the Issue number here. + +#### Questions +Is there something in your PR you're not sure about or need help with? Is there a particular piece of code you would like feedback on? Let us know here! + + diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/.gitignore b/config/zsh/oh-my-zsh-custom/powerlevel9k/.gitignore new file mode 100644 index 0000000..83a6246 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/.gitignore @@ -0,0 +1,3 @@ +test-vm/.vagrant +*.swp +.idea \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/.gitmodules b/config/zsh/oh-my-zsh-custom/powerlevel9k/.gitmodules new file mode 100644 index 0000000..743b8e9 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/.gitmodules @@ -0,0 +1,3 @@ +[submodule "shunit2"] + path = shunit2 + url = https://github.com/kward/shunit2.git diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/.travis.yml b/config/zsh/oh-my-zsh-custom/powerlevel9k/.travis.yml new file mode 100644 index 0000000..30631ea --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/.travis.yml @@ -0,0 +1,77 @@ +language: sh + +os: + - linux + - osx + +osx_image: xcode9.4 + +addons: + apt: + packages: + - build-essential + - git + - mercurial + - subversion + - jq + - node + - golang + - ruby + - python + - python-virtualenv + +before_install: + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi + +env: + global: + - ZSH_DIST=$HOME/.zshdist + matrix: + # Use _ZSH_VERSION since if ZSH_VERSION is present, travis cacher thinks it + # is running in zsh and tries to use zsh specific functions. + - _ZSH_VERSION=5.5.1 + - _ZSH_VERSION=5.5 + - _ZSH_VERSION=5.4.2 + - _ZSH_VERSION=5.4.1 + - _ZSH_VERSION=5.3.1 + - _ZSH_VERSION=5.3 + - _ZSH_VERSION=5.2 + - _ZSH_VERSION=5.1.1 + +cache: + directories: + - $ZSH_DIST + +before_script: + - > + setup_zsh() { + dest="$ZSH_DIST/$1" + if [[ ! -d $dest/bin ]]; then + coreutils_mktemp="mktemp" + if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + coreutils_mktemp="gmktemp" + fi + tmp="$(${coreutils_mktemp} --directory --tmpdir="${TMPDIR:/tmp}" zshbuild.XXXXXX)" + ( + cd "$tmp" && + curl -L http://downloads.sourceforge.net/zsh/zsh-${1}.tar.gz | tar zx && + cd zsh-$1 && + ./configure --prefix="$dest" && + make && + mkdir -p "$dest" && + make install || + echo "Failed to build zsh-${1}!" + ) + fi + export PATH="$dest/bin:$PATH" + } + - setup_zsh $_ZSH_VERSION + # Show the git version being used to test. + - "git --version" + # Show the mercurial version being used to test. + - "hg --version" + # Show the zsh version being used to test. + - "zsh --version" + +script: + - test/suite.spec diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/CHANGELOG.md b/config/zsh/oh-my-zsh-custom/powerlevel9k/CHANGELOG.md new file mode 100644 index 0000000..b40ce50 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/CHANGELOG.md @@ -0,0 +1,450 @@ +## v0.6.6 + +- The `rbenv` segment is no longer a default segment in the LPROMPT. +- PR #959 - Fixing issue in v0.6.5 where we changed some color codes. +- PR #934 - Add Tests +- PR #884 - test-in-docker: fix with newer ZSH versions +- PR #928 - [Docs] Add etc state description in dir docs +- PR #937 - Use SUDO_COMMAND to check for sudo +- PR #925 - [Bugfix] Resolve #918 Transparent background +- PR #923 - Fix font issue debugging script +- PR #921 - Add missing colors to fix color comparison +- PR #951 - Add fallback icon for missing linux distro icons +- PR #956 - Fix broken link in readme +- Fixed #936 - fallback icons for Linux distros +- Fixed #926 - `etc` state for `dir` segment in docs +- Fixed #852 - `sudo` detection got crazy, there. sorry, everyone. +- Fixed #927 - more default color issues. + +## v0.6.5 + +- Multiple PRs: General fixes to README, improved documentation. +- Multiple PRs: Improvements to icons / glyphs. +- PR #777: now possible to always show the Ruby env segment. +- PR #773: Fixed issue with home abbreviation in directory segment. +- PR #789: Now properly working around some odd ZSH status return codes. +- PR #716: Now possible to configure the colors of the VCS segment in rebase mode. +- PR #722: Removed dependency on `bc` for `load` segment. +- PR #686: Fixed issue where whitespaces in path occasionally broke `dir` segment. +- PR #685: No longer accidentally invoking user `grep` aliases. +- PR #680: Using env variable for `PYENV` properly, now. +- PR #676, #611: Fixes for Kubernetes segment. +- PR #667: Supporting multiple AWS profiles. +- PR #660: Fixing directory parsing issue with PYTHONPATH. +- PR #663: Fixed silly issues causing ZSH warnings. +- PR #647: Fixing `public_ip` segment for macOS. +- PR #643: Fixing `vpn_ip` segment naming. +- PR #636: `context` segment now grabs user with command rather than env. +- PR #618: Fix issue where `su -` didn't change context segment. +- PR #608: Load average selection in `load` segment. + +### New Segment: `laravel_version` + +Displays the current laravel version. + +## v0.6.4 + +- `load` segment now has configurable averages. +- Update to `dir` segment to add `dir_writable` feature. +- `status` segment can now display POSIX signal name of exit code. +- Added `teardown` command to turn off P9k prompt. +- Fixes for P9k in Cygwin and 32-bit systems. +- Better colors in virtualization segments. +- Added 'Gopher' icon to the `go_version` segment. +- Improved detection in `nvm` +- Added option to support command status reading from piped command sequences. +- Fixed issue with visual artifacts with quick consecutive commands. +- Updated 'ananconda' segment for more uniform styling. +- `rvm` segment can now support usernames with dashes. +- Fixed Python icon reference in some font configurations. +- Vi mode indicator fixed. +- Fixes for Docker segment. +- Added new Docker-based testing system. +- Significant enhancements to the `battery` segment. Check out the README to + read more! +- New truncation strategy that truncates until the path becomes unique. + +### New Segments: `host` and `user` + +Provides two separate segments for `host` and `user` in case you don't wont both +in one (per the `context` segment). + +### New Segment: `newline` + +Allows you to split segments across multiple lines. + +### New Segment: `kubecontext` + +Shows the current context of your `kubectl` configuration. + +### New Segment: `vpn` + +Shows current `vpn` interface. + +## v0.6.3 + +- Fixed susceptibility to [pw3nage exploit](https://github.com/njhartwell/pw3nage). +- Added support for Android +- The abbreviation for $HOME is now configurable (doesn't have to be `~`). +- Fixed colorization of VCS segment in Subversion repos. +- Improved handling of symlinks in installation paths. + +## v0.6.2 + +- Fixed some issues with the new `nerdfont-fontconfig` option. +- Fixed typo in README. +- The `get_icon_names` function can now print sorted output, and show which + icons users have overridden. +- Added a FreeBSD VM for testing. + +### Add debug script for iTerm2 issues + +A new script `debug/iterm.zsh` was added for easier spotting problems with your iTerm2 configuration. + +### Add debug script for font issues + +A new script `debug/font-issues.zsh` was added, so that problems with your font could be spotted easier. + +### `ram` changes + +The `ram` segment now shows the available ram instead of free. + +### Add new segments `host` and `user` + +The user and host segments allow you to have different icons and colors for both the user and host segments +depending on their state. + +## v0.6.0 + +- Fixed a bug where the tag display was broken on detached HEADs. +- Fixed a bug where SVN detection sometimes failed. +- Fixed the `load` and `ram` segments for BSD. +- Fixed code-points that changed in Awesome fonts. +- Fixed display of "OK_ICON" in `status` segment in non-verbose mode. +- Fixed an issue where dir name truncation that was very short sometimes failed. +- Speed & accuracy improvements to the battery segment. +- Added Github syntax highlighting to README. +- Various documentation cleanup. + +### New Font Option: nerd-fonts + +There is now an option to use [nerd-fonts](https://github.com/ryanoasis/nerd-fonts) with P9k. Simply configure the `nerdfont-fontconfig`, and you'll be set! + +### `vcs` changes + +The VCS segment can now display icons for remote repo hosting services, including Github, Gitlab, and 'other'. + +### `dir` changes + +Added an option to configure the path separator. If you want something +else than an ordinary slash, you could set +`POWERLEVEL9K_DIR_PATH_SEPARATOR` to whatever you want. + +#### `truncate_with_package_name` now searches for `composer.json` as well + +Now `composer.json` files are searched as well. By default `package.json` still takes +precedence. If you want to change that, set `POWERLEVEL9K_DIR_PACKAGE_FILES=(composer.json package.json)`. + +### New segment `command_execution_time` added + +Shows the duration a command needed to run. By default only durations over 3 seconds +are shown (can be adjusted by setting POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD). + +### New segment `dir_writable` added + +This segment displays a lock icon if your user has no write permissions in the current folder. + +### New segment `disk_usage` added + +This segment will show the usage level of your current partition. + +### New segment `public_ip` added + +Fetches your Public IP (using ident.me) and displays it in your prompt. + +### New segment `swift_version` added + +This segment displays the version of Swift that is installed / in your path. + +### New segment `detect_virt` added + +Detects and reports if you are in a virtualized session using `systemd`. + +## v0.5.0 + +### `load` and `ram` changes + +These two segments now support BSD. + +### `vcs` changes + +- We implemented a huge speed improvement for this segment. +- Now this segment supports Subversion repositories. +- Add ability to hide tags by setting `POWERLEVEL9K_VCS_HIDE_TAGS` to true. + +## `anaconda` changes + +Speed improvements for `anaconda` segment. + +## v0.4.0 + +### Development changes + +From now on, development makes use of a CI system "travis". + +### `vcs` changes + +The default state was renamed to `clean`. If you overrode foreground +or background color in the past, you need to rename your variables to: + +```zsh +POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan' +POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white' +``` + +Additionaly the vcs segment now has an `untracked` state which +indicates that you have untracked files in your repository. + +The foreground color of actionformat is now configurable via: +```zsh +POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND='green' +``` + +Also, the vcs segment uses the foreground color it was configured to. +That said, the variables `POWERLEVEL9K_VCS_FOREGROUND` and +`POWERLEVEL9K_VCS_DARK_FOREGROUND` are no longer used. Instead use +the proper variable `POWERLEVEL9K_VCS__FOREGROUND` to change +foreground color. + +### `dir` Shortening Strategies + +There is now a path shortening strategy that will use the `package.json` file to +shorten your directory path. See the documentation for the `dir` segment for more +details. + +Also, the shorten delimiter was changed to an unicode ellipsis. It is configurable +via `POWERLEVEL9K_SHORTEN_DELIMITER`. + +### `rbenv` changes + +The `rbenv` segment now makes use of the full rbenv command, so the correct +ruby version is now shown if it differs from the globally one. + +### `node`, `nvm` Segments + +Improvements to speed / reliability. + +### `ram` changes + +The `ram` segment was split up into `ram` and `swap`. The +`POWERLEVEL9K_RAM_ELEMENTS` variable is obsolete. + +### New segment `swap` added + +Due to the split up of the ram segment, this one was created. It +shows the currently used swap size. + +### New segment `nodeenv` added + +Added new `nodeenv` segment that shows the currently used node environment. + +### New segment `aws_eb_env` added + +This segment displays the current Elastic Beanstalk environment. + +### New segment `chruby` added + +Added new `chruby` segment to support this version manager. + +### New segment `docker_machine` added + +Added new `docker_machine` segment that will show your Docker machine. + +### New segment `anaconda` added + +A new segment `anaconda` was added that shows the current used +anaconda environment. + +## New segment `pyenv` added + +This segment shows your active python version as reported by `pyenv`. + + +## v0.3.2 + +### `vcs` changes + +A new state `UNTRACKED` was added to the `vcs` segment. So we now +have 3 states for repositories: `UNTRACKED`, `MODIFIED`, and the +default state. The `UNTRACKED` state is active when there are files +in the repository directory which have not been added to the repo +(the same as when the `+` icon appears). The default color for the +`UNTRACKED` state is now yellow, and the default color for the +`MODIFIED` state is now read, but those colors can be changed by +setting these variables, for example: + +```zsh +POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='black' +POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='white' +POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND='green' +POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND='blue' +``` + +## v0.3.1 + +### `dir` changes + +A new state `HOME_SUBFOLDER` was added. So if you want to overwrite +colors for this segment, also set this variables: +```zsh +POWERLEVEL9K_DIR_HOME_SUBFOLDER_BACKGROUND='black' +POWERLEVEL9K_DIR_HOME_SUBFOLDER_FOREGROUND='white' +``` + +### `background_jobs` changes +Now displays the number of background jobs if there's more than 1. +You can disable it by setting : +```zsh +POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE=false +``` + +## v0.3.0 + +### Introduced "visual identifiers" to the segments + +Now almost every segment can have a visual identifier, which is an +icon whose color could be adjusted by users. + +### Added ability for "joined" segments + +You can now merge segments together by suffixing the segment name with "_joined". +For Developers: Be aware that the order of parameters in left/right_prompt_segment +has changed. Now a boolean parameter must be set as second parameter (true if joined). + +### `dir` changes + +This segment now has "state", which means you now can change the colors seperatly +depending if you are in your homefolder or not. +Your variables for that should now look like: +```zsh +POWERLEVEL9K_DIR_HOME_BACKGROUND='green' +POWERLEVEL9K_DIR_HOME_FOREGROUND='cyan' +POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='red' +POWERLEVEL9K_DIR_DEFAULT_FOREGROUND='yellow' +``` + +### `status` changes + +The `status` segment was split up into three segments. `background_jobs` prints +an icon if there are background jobs. `root_indicator` prints an icon if the user +is root. The `status` segment focuses now on the status only. +The `status` segment also now has "state". If you want to overwrite the colors, +you have to add the state to your variables: +```zsh +POWERLEVEL9K_STATUS_ERROR_BACKGROUND='green' +POWERLEVEL9K_STATUS_ERROR_FOREGROUND='cyan' +POWERLEVEL9K_STATUS_OK_BACKGROUND='red' +POWERLEVEL9K_STATUS_OK_FOREGROUND='yellow' +``` + +### New segment `custom_command` added + +A new segment that allows users to define a custom command was added. + +### `virtualenv` changes + +This segment now respects `VIRTUAL_ENV_DISABLE_PROMPT`. If this variable is set +to `true`, the segments does not get rendered. + +### `load` changes + +The `load` segement was split and a new segment `ram` was extracted. This new +segment is able to show the free ram and used swap. + +### `vcs` changes + +This prompt uses the `VCS_INFO` subsystem by ZSH. From now on this subsystem +is only invoked if a `vcs` segment was configured. + +### `rvm` changes + +This segment now does not invoke RVM directly anymore. Instead, is relys on the +circumstance that RVM was invoked beforehand and just reads the environment +variables '$GEM_HOME' and '$MY_RUBY_HOME'. It also now displays the used gemset. + +### New segment `battery` added + +A new segment that shows the battery status of your laptop was added. + +### New segment `go_version` added + +This segment shows the GO version. + +### New segment `nvm` added + +This segment shows your NodeJS version by using NVM (and if it is not 'default'). + +### New segment `todo` added + +This segment shows your ToDos from [todo.sh](http://todotxt.com/). + +### New segment `rust_version` added + +This segment shows your local rust version. + +## v0.2.0 + +### `longstatus` is now `status` + +The segments got merged together. To show the segment only if an error occurred, +set `POWERLEVEL9K_STATUS_VERBOSE=false` (this is the same behavior as the old +`status` segment. + +### Icon overriding mechanism added + +All icons can now be overridden by setting a variable named by the internal icon +name. You can get a full list of icon name by calling `get_icon_names`. + +### Same color segements get visual separator + +This separator can be controlled by setting `POWERLEVEL9K_LEFT_SUBSEGMENT_SEPARATOR` +or `POWERLEVEL9K_RIGHT_SUBSEGMENT_SEPARATOR`. By default this separator is +printed in the foreground color. + +### `dir` segment has different strategies for truncation + +Now you can choose between `truncate_middle` or `truncate_from_right` by setting +`POWERLEVEL9K_SHORTEN_STRATEGY`. Default behavior is unchanged (truncate whole +directories). `POWERLEVEL9K_SHORTEN_DIR_LENGTH` can be used to influence how +much will be truncated (either direcories or chars). + +### New segment `ip` added + +This segment shows your internal IP address. You can define which interfaces IP +will be shown by specifying it via `POWERLEVEL9K_IP_INTERFACE`. + +### New segment `load` added + +This segment shows your computers 5min load average. + +### New segment `os_icon` added + +This segment shows a little indicator which OS you are running. + +### New segment `php_version` added + +This segment shows your PHP version. + +### New segment `vi_mode` added + +This segment gives you a hint in which VI-mode you currently are. This +segment requires a proper configured VI-mode. + +### Added the ability to have empty left or right prompts + +By setting the according variable to an empty array, the left or right +prompt will be empty. + +## v0.1.0 + +This is the first release diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/CODE_OF_CONDUCT.md b/config/zsh/oh-my-zsh-custom/powerlevel9k/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..22c9ebb --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/CODE_OF_CONDUCT.md @@ -0,0 +1,46 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at bhilburn@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/LICENSE b/config/zsh/oh-my-zsh-custom/powerlevel9k/LICENSE new file mode 100644 index 0000000..812d306 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2014-2017 Ben Hilburn + +MIT LICENSE + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "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. diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/README.md b/config/zsh/oh-my-zsh-custom/powerlevel9k/README.md new file mode 100644 index 0000000..2ecf297 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/README.md @@ -0,0 +1,765 @@ +![](https://raw.githubusercontent.com/bhilburn/powerlevel9k-logo/master/logo-banner.png) +--- +[![Build Status](https://travis-ci.org/bhilburn/powerlevel9k.svg?branch=master)](https://travis-ci.org/bhilburn/powerlevel9k) +[![Join the chat at https://gitter.im/bhilburn/powerlevel9k](https://badges.gitter.im/bhilburn/powerlevel9k.svg)](https://gitter.im/bhilburn/powerlevel9k?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +Powerlevel9k is a theme for ZSH which uses [Powerline +Fonts](https://github.com/powerline/fonts). It can be used with vanilla ZSH or +ZSH frameworks such as [Oh-My-Zsh](https://github.com/robbyrussell/oh-my-zsh), +[Prezto](https://github.com/sorin-ionescu/prezto), +[Antigen](https://github.com/zsh-users/antigen), and [many +others](https://github.com/bhilburn/powerlevel9k/wiki/Install-Instructions). + +Get more out of your terminal. Be a badass. Impress everyone in 'Screenshot Your +Desktop' threads. Use powerlevel9k. + +![](http://bhilburn.org/content/images/2015/01/pl9k-improved.png) + +You can check out some other users' configurations in our wiki: [Show Off Your +Config](https://github.com/bhilburn/powerlevel9k/wiki/Show-Off-Your-Config). + +There are a number of Powerline ZSH themes available, now. The developers of +this theme focus on four primary goals: + +1. Give users a great out-of-the-box configuration with no additional + configuration required. +2. Make customization easy for users who do want to tweak their prompt. +3. Provide useful segments that you can enable to make your prompt even more + effective and helpful. We have prompt segments for everything from unit test + coverage to your AWS instance. +4. Optimize the code for execution speed as much as possible. A snappy terminal + is a happy terminal. + +Powerlevel9k can be used to create both very useful and beautiful terminal environments: + +![](https://camo.githubusercontent.com/b5d7eb49a30bfe6bdb5706fa3c9be95fe8e5956e/687474703a2f2f67696679752e636f6d2f696d616765732f70396b6e65772e676966) + +### Table of Contents + +1. [Installation](#installation) +2. [Customization](#prompt-customization) + 1. [Stylizing Your Prompt](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt) + 2. [Customizing Prompt Segments](#customizing-prompt-segments) + 3. [Available Prompt Segments](#available-prompt-segments) +3. [Troubleshooting](https://github.com/bhilburn/powerlevel9k/wiki/Troubleshooting) + +Be sure to also [check out the Wiki](https://github.com/bhilburn/powerlevel9k/wiki)! + +### Installation +There are two installation steps to go from a vanilla terminal to a PL9k +terminal. Once you are done, you can optionally customize your prompt. + +[Installation Instructions](https://github.com/bhilburn/powerlevel9k/wiki/Install-Instructions) + +1. [Install the Powerlevel9k Theme](https://github.com/bhilburn/powerlevel9k/wiki/Install-Instructions#step-1-install-powerlevel9k) +2. [Install Powerline Fonts](https://github.com/bhilburn/powerlevel9k/wiki/Install-Instructions#step-2-install-a-powerline-font) + +No configuration is necessary post-installation if you like the default +settings, but there are plenty of segment customization options available if you +are interested. + +### Prompt Customization + +Be sure to check out the wiki page on the additional prompt customization +options, including color and icon settings: [Stylizing Your Prompt](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt) + +#### Customizing Prompt Segments +Customizing your prompt is easy! Select the segments you want to have displayed, +and then assign them to either the left or right prompt by adding the following +variables to your `~/.zshrc`. + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_LEFT_PROMPT_ELEMENTS`|`(context dir vcs)`|Segment list for left prompt| +|`POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS`|`(status root_indicator background_jobs history time)`|Segment list for right prompt| + + +The table above shows the default values, so if you wanted to set these +variables manually, you would put the following in +your `~/.zshrc`: +```zsh +POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir vcs) +POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs history time) +``` +#### Available Prompt Segments +The segments that are currently available are: + +**System Status Segments:** +* [`background_jobs`](#background_jobs) - Indicator for background jobs. +* [`battery`](#battery) - Current battery status. +* [`context`](#context) - Your username and host, conditionalized based on $USER and SSH status. +* [`date`](#date) - System date. +* [`dir`](#dir) - Your current working directory. +* `dir_writable` - Displays a lock icon, if you do not have write permissions on the current folder. +* [`disk_usage`](#disk_usage) - Disk usage of your current partition. +* `history` - The command number for the current line. +* [`host`](#host) - Your current host name +* [`ip`](#ip) - Shows the current IP address. +* [`vpn_ip`](#vpn_ip) - Shows the current VPN IP address. +* [`public_ip`](#public_ip) - Shows your public IP address. +* [`load`](#load) - Your machine's load averages. +* `os_icon` - Display a nice little icon, depending on your operating system. +* `ram` - Show free RAM. +* `root_indicator` - An indicator if the user has superuser status. +* [`status`](#status) - The return code of the previous command. +* `swap` - Prints the current swap size. +* [`time`](#time) - System time. +* [`user`](#user) - Your current username +* [`vi_mode`](#vi_mode)- Your prompt's Vi editing mode (NORMAL|INSERT). +* `ssh` - Indicates whether or not you are in an SSH session. + +**Development Environment Segments:** +* [`vcs`](#vcs) - Information about this `git` or `hg` repository (if you are in one). + +**Language Segments:** +* **GoLang Segments:** + * `go_version` - Show the current GO version. +* **Javascript / Node.js Segments:** + * `node_version` - Show the version number of the installed Node.js. + * `nodeenv` - [nodeenv](https://github.com/ekalinin/nodeenv) prompt for displaying node version and environment name. + * `nvm` - Show the version of Node that is currently active, if it differs from the version used by NVM +* **PHP Segments:** + * `php_version` - Show the current PHP version. + * `laravel_version` - Show the current Laravel version. + * [`symfony2_tests`](#symfony2_tests) - Show a ratio of test classes vs code classes for Symfony2. + * `symfony2_version` - Show the current Symfony2 version, if you are in a Symfony2-Project dir. +* **Python Segments:** + * `virtualenv` - Your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/). + * [`anaconda`](#anaconda) - Your active [Anaconda](https://www.continuum.io/why-anaconda) environment. + * `pyenv` - Your active python version as reported by the first word of [`pyenv version`](https://github.com/yyuu/pyenv). Note that the segment is not displayed if that word is _system_ i.e. the segment is inactive if you are using system python. +* **Ruby Segments:** + * [`chruby`](#chruby) - Ruby environment information using `chruby` (if one is active). + * [`rbenv`](#rbenv) - Ruby environment information using `rbenv` (if one is active). + * [`rspec_stats`](#rspec_stats) - Show a ratio of test classes vs code classes for RSpec. + * `rvm` - Ruby environment information using `$GEM_HOME` and `$MY_RUBY_HOME` (if one is active). +* **Rust Segments:** + * `rust_version` - Display the current rust version and [logo](https://www.rust-lang.org/logos/rust-logo-blk.svg). +* **Swift Segments:** + * `swift_version` - Show the version number of the installed Swift. +* **Java Segments:** + * `java_version` - Show the current Java version. + +**Cloud Segments:** +* **AWS Segments:** + * [`aws`](#aws) - The current AWS profile, if active. + * `aws_eb_env` - The current Elastic Beanstalk Environment. +* `docker_machine` - The current Docker Machine. +* `kubecontext` - The current context of your `kubectl` configuration. +* `dropbox` - Indicates Dropbox directory and syncing status using `dropbox-cli` + +**Other:** +* [`custom_command`](#custom_command) - Create a custom segment to display the + output of an arbitrary command. +* [`command_execution_time`](#command_execution_time) - Display the time the current command took to execute. +* [`todo`](http://todotxt.com/) - Shows the number of tasks in your todo.txt tasks file. +* `detect_virt` - Virtualization detection with systemd +* `newline` - Continues the prompt on a new line. +* `openfoam` - Shows the currently sourced [OpenFOAM](https://openfoam.org/) environment. + +--------------------------------------------------------------------------------- + + +##### anaconda + +This segment shows your active anaconda environment. It relies on either the +`CONDA_ENV_PATH` or the `CONDA_PREFIX` (depending on the `conda` version) +environment variable to be set which happens when you properly `source +activate` an environment. + +Special configuration variables: + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_ANACONDA_LEFT_DELIMITER`|"("|The left delimiter just before the environment name.| +|`POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER`|")"|The right delimiter just after the environment name.| + +Additionally the following segment specific parameters can be used to customize +it: `POWERLEVEL9K_PYTHON_ICON`, `POWERLEVEL9K_ANACONDA_BACKGROUND`, and +`POWERLEVEL9K_ANACONDA_FOREGROUND`. + +##### aws + +If you would like to display the [current AWS +profile](http://docs.aws.amazon.com/cli/latest/userguide/installing.html), add +the `aws` segment to one of the prompts, and define `AWS_DEFAULT_PROFILE` in +your `~/.zshrc`: + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`AWS_DEFAULT_PROFILE`|None|Your AWS profile name| + +##### background_jobs + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE`|`true`|If there is more than one background job, this segment will show the number of jobs. Set this to `false` to turn this feature off.| +`POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE_ALWAYS`|`false`|Always show the jobs count (even if it's zero).| + +##### battery + +The default settings for this segment will display your current battery status (fails gracefully on +systems without a battery). It is supported on both OSX and Linux (note that it requires `acpi` on Linux). + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_BATTERY_CHARGING`|`"yellow"`|Color to indicate a charging battery.| +|`POWERLEVEL9K_BATTERY_CHARGED`|`"green"`|Color to indicate a charged battery.| +|`POWERLEVEL9K_BATTERY_DISCONNECTED`|`$DEFAULT_COLOR`|Color to indicate absence of battery.| +|`POWERLEVEL9K_BATTERY_LOW_THRESHOLD`|`10`|Threshold to consider battery level critical.| +|`POWERLEVEL9K_BATTERY_LOW_COLOR`|`"red"`|Color to indicate critically low charge level.| +|`POWERLEVEL9K_BATTERY_VERBOSE`|`true`|Display time remaining next to battery level.| + +Note that you can [modify the `_FOREGROUND` +color](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#segment-color-customization) +without affecting the icon color. + +You can also change the battery icon automatically depending on the battery +level. This will override the default battery icon. In order to do this, you +need to define the `POWERLEVEL9k_BATTERY_STAGES` variable. + + +| Variable | Default Value | Description | +|-------------------------------|---------------|---------------------------------------------------------------| +| `POWERLEVEL9K_BATTERY_STAGES` | Unset | A string or array, which each index indicates a charge level. | + +Powerlevel9k will use each index of the string or array as a stage to indicate battery +charge level, progressing from left to right. You can provide any number of +stages. The setting below, for example, provides 8 stages for Powerlevel9k to use. +```zsh +POWERLEVEL9K_BATTERY_STAGES="▁▂▃▄▅▆▇█" +``` + +If you require extra spacing after the icon, you will have to set it as an array, +since spaces in the string will be used as one of the stages and you will get a +missing icon. To do this, declare the variable as follows: +```zsh +POWERLEVEL9K_BATTERY_STAGES=($'\u2581 ' $'\u2582 ' $'\u2583 ' $'\u2584 ' $'\u2585 ' $'\u2586 ' $'\u2587 ' $'\u2588 ') +``` + +Using the array syntax, you can create stages comprised of multiple characters. +The below setting provides 40 battery stages. +```zsh +POWERLEVEL9K_BATTERY_STAGES=( + $'▏ ▏' $'▎ ▏' $'▍ ▏' $'▌ ▏' $'▋ ▏' $'▊ ▏' $'▉ ▏' $'█ ▏' + $'█▏ ▏' $'█▎ ▏' $'█▍ ▏' $'█▌ ▏' $'█▋ ▏' $'█▊ ▏' $'█▉ ▏' $'██ ▏' + $'██ ▏' $'██▎ ▏' $'██▍ ▏' $'██▌ ▏' $'██▋ ▏' $'██▊ ▏' $'██▉ ▏' $'███ ▏' + $'███ ▏' $'███▎ ▏' $'███▍ ▏' $'███▌ ▏' $'███▋ ▏' $'███▊ ▏' $'███▉ ▏' $'████ ▏' + $'████ ▏' $'████▎▏' $'████▍▏' $'████▌▏' $'████▋▏' $'████▊▏' $'████▉▏' $'█████▏' ) +``` + +You can also change the background of the segment automatically depending on the +battery level. This will override the following variables: +`POWERLEVEL9K_BATTERY_CHARGING`, `POWERLEVEL9K_BATTERY_CHARGED`, +`POWERLEVEL9K_BATTERY_DISCONNECTED`, and `POWERLEVEL9K_BATTERY_LOW_COLOR`. In +order to do this, define a color array, from low to high, as shown below: +```zsh +POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND=(red1 orangered1 darkorange orange1 gold1 yellow1 yellow2 greenyellow chartreuse1 chartreuse2 green1) +``` + +As with the battery stages, you can use any number of colors and Powerlevel9k +will automatically use all of them appropriately. + +Some example settings: + +| Brightness | Possible Array | +|----------------|---------------------------------------------------------------------------------------------------------------| +| Bright Colors | `(red1 orangered1 darkorange orange1 gold1 yellow1 yellow2 greenyellow chartreuse1 chartreuse2 green1)` | +| Normal Colors | `(red3 darkorange3 darkgoldenrod gold3 yellow3 chartreuse2 mediumspringgreen green3 green3 green4 darkgreen)` | +| Subdued Colors | `(darkred orange4 yellow4 yellow4 chartreuse3 green3 green4 darkgreen)` | + +##### chruby + +This segment shows the version of Ruby being used when using `chruby` to change your current Ruby stack. + +It uses `$RUBY_ENGINE` and `$RUBY_VERSION` as set by `chruby`. + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_CHRUBY_SHOW_ENGINE`|true|Show the currently selected Ruby engine (e.g. `ruby`, `jruby`, `rbx`, etc) +|`POWERLEVEL9K_CHRUBY_SHOW_VERSION`|true|Shows the currently selected engine's version (e.g. `2.5.1`) + +##### command_execution_time + +Display the time the previous command took to execute if the time is above +`POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD`. The time is formatted to be +"human readable", and so scales the units based on the length of execution time. +If you want more precision, just set the +`POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION` field. + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD`|3|Threshold above which to print this segment. Can be set to `0` to always print.| +|`POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION`|2|Number of digits to use in the fractional part of the time value.| + +##### custom_command + +The `custom_...` segment allows you to turn the output of a custom command into +a prompt segment. As an example, if you wanted to create a custom segment to +display your WiFi signal strength, you might define a custom segment called +`custom_wifi_signal` like this: +```zsh +POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context time battery dir vcs virtualenv custom_wifi_signal) +POWERLEVEL9K_CUSTOM_WIFI_SIGNAL="echo signal: \$(nmcli device wifi | grep yes | awk '{print \$8}')" +POWERLEVEL9K_CUSTOM_WIFI_SIGNAL_BACKGROUND="blue" +POWERLEVEL9K_CUSTOM_WIFI_SIGNAL_FOREGROUND="yellow" +``` +If you prefer, you can also define the function in your `.zshrc` rather than +putting it in-line with the variable export, as shown above. Just don't forget +to invoke your function from your segment! Example code that achieves the same +result as the above: +```zsh +zsh_wifi_signal(){ + local signal=$(nmcli device wifi | grep yes | awk '{print $8}') + local color='%F{yellow}' + [[ $signal -gt 75 ]] && color='%F{green}' + [[ $signal -lt 50 ]] && color='%F{red}' + echo -n "%{$color%}\uf230 $signal%{%f%}" # \uf230 is  +} + +POWERLEVEL9K_CUSTOM_WIFI_SIGNAL="zsh_wifi_signal" +POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context time battery dir vcs virtualenv custom_wifi_signal) +``` +The command, above, gives you the wireless signal segment shown below: + +![signal](http://i.imgur.com/hviMATC.png) + +You can define as many custom segments as you wish. If you think you have +a segment that others would find useful, please consider upstreaming it to the +main theme distribution so that everyone can use it! + +##### context + +The `context` segment (user@host string) is conditional. By default, it will +only print if you are not your 'normal' user (including if you are root), or if +you are SSH'd to a remote host. `SUDO` and `REMOTE_SUDO` states are also available to show whether the current user or remote user has superuser privileges. + +To use this feature, make sure the `context` segment is enabled in your prompt +elements (it is by default), and define a `DEFAULT_USER` in your `~/.zshrc`. + +You can customize the `context` segment. For example, you can make it to print the +full hostname by setting + +``` +POWERLEVEL9K_CONTEXT_TEMPLATE="%n@`hostname -f`" +``` + +You can set the `POWERLEVEL9K_CONTEXT_HOST_DEPTH` variable to change how the +hostname is displayed. See [ZSH Manual](http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Login-information) +for details. The default is set to %m which will show the hostname up to the first ‘.’ +You can set it to %{N}m where N is an integer to show that many segments of system +hostname. Setting N to a negative integer will show that many segments from the +end of the hostname. + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`DEFAULT_USER`|None|Username to consider a "default context" (you can also set `$USER`).| +|`POWERLEVEL9K_ALWAYS_SHOW_CONTEXT`|false|Always show this segment, including $USER and hostname.| +|`POWERLEVEL9K_ALWAYS_SHOW_USER`|false|Always show the username, but conditionalize the hostname.| +|`POWERLEVEL9K_CONTEXT_TEMPLATE`|%n@%m|Default context prompt (username@machine). Refer to the [ZSH Documentation](http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html) for all possible expansions, including deeper host depths.| + +This segment can have different states. They might help you to visualize your +different privileges. Read more about styling with states [here](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#special-segment-colors). + +| State | Meaning | +|---------------|----------------------------------------------------------| +| `DEFAULT` | You are a normal user | +| `ROOT` | You are the root user | +| `SUDO` | You are using elevated rights | +| `REMOTE_SUDO` | You are SSH'ed into the machine and have elevated rights | +| `REMOTE` | You are SSH'ed into the machine | + +##### date + +The `date` segment shows the current system date. + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_DATE_FORMAT`|`%D{%d.%m.%y}`|[ZSH time format](http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Date-and-time) to use in this segment.| + +##### dir + +The `dir` segment shows the current working directory. When using the "Awesome +Powerline" fonts, there are additional glyphs, as well: + +| `Compatible` | `Powerline` | `Awesome Powerline` | Situation +|------------|-----------|-------------------|---------------------------- +| None | None | ![](https://cloud.githubusercontent.com/assets/1544760/12183451/40ec4016-b58f-11e5-9b9e-74e2b2f0b8b3.png) | At the root of your home folder | +| None | None | ![](https://cloud.githubusercontent.com/assets/1544760/12369315/8a5d762c-bbf5-11e5-8a20-ca1179f48d6c.png) | Within a subfolder of your home directory | +| None | None | ![](https://cloud.githubusercontent.com/assets/1544760/12183452/40f79286-b58f-11e5-9b8c-ed1343a07b08.png) | Outside of your home folder | +| None | None | ⚙ | Within the `/etc` directory | + +To turn off these icons you could set these variables to an empty string. +```zsh +POWERLEVEL9K_HOME_ICON='' +POWERLEVEL9K_HOME_SUB_ICON='' +POWERLEVEL9K_FOLDER_ICON='' +POWERLEVEL9K_ETC_ICON='' +``` +You can limit the output to a certain length by truncating long paths. +Customizations available are: + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_DIR_PATH_ABSOLUTE`|None|If set to `true`, will use absolute paths instead of home folder abbreviation `~`| +|`POWERLEVEL9K_SHORTEN_DIR_LENGTH`|`2`|If your shorten strategy, below, is entire directories, this field determines how many directories to leave at the end. If your shorten strategy is by character count, this field determines how many characters to allow per directory string.| +|`POWERLEVEL9K_SHORTEN_STRATEGY`|None|How the directory strings should be truncated. See the table below for more informations.| +|`POWERLEVEL9K_SHORTEN_DELIMITER`|`..`|Delimiter to use in truncated strings. This can be any string you choose, including an empty string if you wish to have no delimiter.| + +| Strategy Name | Description | +|---------------|-------------| +|Default|Truncate whole directories from left. How many is defined by `POWERLEVEL9K_SHORTEN_DIR_LENGTH`| +|`truncate_absolute_chars`|Truncates an absolute number of characters from the left such that the number of characters that your path displays (with or without `POWERLEVEL9K_SHORTEN_DELIMITER`) is no more than `POWERLEVEL9K_SHORTEN_DIR_LENGTH` + the length of `POWERLEVEL9K_SHORTEN_DELIMITER` | +|`truncate_middle`|Truncates the middle part of a folder. E.g. you are in a folder named `~/MySuperProjects/AwesomeFiles/BoringOffice`, then it will truncated to `~/MyS..cts/Awe..les/BoringOffice`, if `POWERLEVEL9K_SHORTEN_DIR_LENGTH=3` is also set (controls the amount of characters to be left).| +|`truncate_from_right`|Just leaves the beginning of a folder name untouched. E.g. your folders will be truncated like so: "/ro../Pr../office". How many characters will be untouched is controlled by `POWERLEVEL9K_SHORTEN_DIR_LENGTH`.| +|`truncate_absolute`|Truncates everything exept the last few characters in the path. E.g. if you are in a folder named "~/Projects/powerlevel9k" and you have set `POWERLEVEL9K_SHORTEN_DIR_LENGTH=3`, you will get "..l9k".| +|`truncate_to_last`|Truncates everything before the last folder in the path.| +|`truncate_to_first_and_last`|Truncate middle directories from the path. How many directories will be untouched is controlled by POWERLEVEL9K_SHORTER_DIR_LENGTH. E.g. if you are in a folder named "~/Projects/powerlevel9k" and you have set `POWERLEVEL9K_SHORTEN_DIR_LENGTH=1`, you will get "~/../powerlevel9k".|| +|`truncate_to_unique`|Parse all parent path components and truncate them to the shortest unique length. If you copy & paste the result to a shell, after hitting `TAB` it should expand to the original path unambiguously.| +|`truncate_with_package_name`|Search for a `package.json` or `composer.json` and prints the `name` field to abbreviate the directory path. The precedence and/or files could be set by `POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json)`. If you have [jq](https://stedolan.github.io/jq/) installed, it will dramatically improve the speed of this strategy.| +|`truncate_with_folder_marker`|Search for a file that is specified by `POWERLEVEL9K_SHORTEN_FOLDER_MARKER` and truncate everything before that (if found, otherwise stop on $HOME and ROOT).| + +For example, if you wanted the truncation behavior of the `fish` shell, which +truncates `/usr/share/plasma` to `/u/s/plasma`, you would use the following: +```zsh +POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 +POWERLEVEL9K_SHORTEN_DELIMITER="" +POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" +``` +In each case you have to specify the length you want to shorten the directory +to. So in some cases `POWERLEVEL9K_SHORTEN_DIR_LENGTH` means characters, in +others whole directories. + +The `truncate_with_package_name` strategy gives your directory path relative to the root of your project. For example, if you have a project inside `$HOME/projects/my-project` with a `package.json` that looks like: + +```json +{ + "name": "my-cool-project" +} +``` + +The path shown would be `my-cool-project`. If you navigate to `$HOME/projects/my-project/src`, then the path shown would be `my-cool-project/src`. Please note that this currently looks for `.git` directory to determine the root of the project. + +If you want to customize the directory separator, you could set: +```zsh +# Double quotes are important here! +POWERLEVEL9K_DIR_PATH_SEPARATOR="%F{red} $(print_icon 'LEFT_SUBSEGMENT_SEPARATOR') %F{black}" +``` +To omit the first character (usually a slash that gets replaced if you set `POWERLEVEL9K_DIR_PATH_SEPARATOR`), +you could set `POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true`. + +You can also customize the leading tilde character when you are in `$HOME` using: +```zsh +# Double quotes are important here! +POWERLEVEL9K_HOME_FOLDER_ABBREVIATION="%F{red} $(print_icon 'HOME_ICON') %F{black}" +``` +You can also configure the `dir` segment to show when you are in a directory without write permissions, using the variable below. + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_DIR_SHOW_WRITABLE`|`false`|If set to `true` and you are in a directory that you do not have write permissions for, this segment will display a lock icon and enter the `NOT_WRITABLE` state (which can be customized per [our usual process](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#segment-color-customization)). Note that this functionality is also available in a separate segment, `dir_writable`.| + +If you want to customize the last directory of the path, you can now set `POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND` to a custom color and/or `POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true` to display that part in bold. + +You can also color the separator separately by setting the color using `POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND`. + +##### disk_usage + +The `disk_usage` segment will show the usage level of the partition that your current working directory resides in. It can be configured with the following variables. + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|POWERLEVEL9K_DISK_USAGE_ONLY_WARNING|false|Hide the segment except when usage levels have hit warning or critical levels.| +|POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL|90|The usage level that triggers a warning state.| +|POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL|95|The usage level that triggers a critical state.| + +##### host + +The `host` segment will print the hostname. + +You can set the `POWERLEVEL9K_HOST_TEMPLATE` variable to change how the hostname +is displayed. See (ZSH Manual)[http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Login-information] +for details. The default is set to `%m` which will show the hostname up to the +first `.`. You can set it to `%{N}m` where N is an integer to show that many +segments of system hostname. Setting `N` to a negative integer will show that many +segments from the end of the hostname. + +``` +POWERLEVEL9K_HOST_TEMPLATE="%2m" +``` + +By default, LOCAL hosts will show the host icon and remote hosts will show the SSH icon. You can override them by setting +``` +POWERLEVEL9K_HOST_ICON="\uF109 " +POWERLEVEL9K_SSH_ICON="\uF489 " +``` + + +##### ip + +This segment tries to examine all currently used network interfaces and prints +the first address it finds. In the case that this is not the right NIC, you can +specify the correct network interface by setting: + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_IP_INTERFACE`|None|The NIC for which you wish to display the IP address. Example: `eth0`.| + +##### vpn_ip + +This segment tries to extract the VPN related IP addresses from nmcli, based on the NIC type: + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_VPN_IP_INTERFACE`|`tun`|The VPN interface.| + +##### public_ip + +This segment will display your public IP address. There are several methods of obtaining this +information and by default it will try all of them starting with the most efficient. You can +also specify which method you would like it to use. The methods available are dig using opendns, +curl, or wget. The host used for wget and curl is http://ident.me by default but can be set to +another host if you prefer. + +If you activate a VPN, the icon for this segment will change to the defined VPN icon. + +The public_ip segment will attempt to update your public IP address every 5 minutes by default(also +configurable by the user). If you lose connection your cached IP address will be displayed until +your timeout expires at which point every time your prompt is generated a new attempt will be made. +Until an IP is successfully pulled the value of $POWERLEVEL9K_PUBLIC_IP_NONE will be displayed for +this segment. If this value is empty(the default)and $POWERLEVEL9K_PUBLIC_IP_FILE is empty the +segment will not be displayed. + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_PUBLIC_IP_FILE`|'/tmp/p9k_public_ip'|This is the file your public IP is cached in.| +|`POWERLEVEL9K_PUBLIC_IP_HOST`|'http://ident.me'|This is the default host to get your public IP.| +|`POWERLEVEL9K_PUBLIC_IP_TIMEOUT`|300|The amount of time in seconds between refreshing your cached IP.| +|`POWERLEVEL9K_PUBLIC_IP_METHODS`|(dig curl wget)| These methods in that order are used to refresh your IP.| +|`POWERLEVEL9K_PUBLIC_IP_NONE`|None|The string displayed when an IP was not obtained| + +##### load + +Displays one of your load averages with appropriate state coloring. The thresholds are: +- `0.7 * NUM_CORES <`: critical +- `0.5 * NUM_CORES <`: warning +- `less`: normal + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_LOAD_WHICH`|5|Which average to show. Possible values: 1, 5 or 15| + +##### newline + +Puts a newline in your prompt so you can continue using segments on the next +line. This allows you to use segments on both lines, unlike +`POWERLEVEL9K_PROMPT_ON_NEWLINE`, which simply separates segments from the +prompt itself. + +This only works on the left side. On the right side it does nothing. + +##### rbenv + +This segment shows the version of Ruby being used when using `rbenv` to change your current Ruby stack. + +It figures out the version being used by taking the output of the `rbenv version-name` command. + +* If `rbenv` is not in $PATH, nothing will be shown. +* By default, if the current local Ruby version is the same as the global Ruby version, nothing will be shown. See the configuration variable, below, to modify this behavior. + +Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_RBENV_ALWAYS`|'false'|Always show the `rbenv` segment, even if the local version matches the global.| + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW`|`false`|Set to true if you wish to show the rbenv segment even if the current Ruby version is the same as the global Ruby version| + +##### pyenv + +This segment shows the version of Python being used when using `pyenv` to change your current Python stack. + +The `PYENV_VERSION` environment variable will be used if specified. Otherwise it figures out the version being used by taking the output of the `pyenv version-name` command. + +* If `pyenv` is not in $PATH, nothing will be shown. +* If the current Python version is the same as the global Python version, nothing will be shown. + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW`|`false`|Set to true if you wish to show the pyenv segment even if the current Python version is the same as the global Python version| + +##### rspec_stats + +See [Unit Test Ratios](#unit-test-ratios), below. + +##### status + +This segment shows the return code of the last command. + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_STATUS_CROSS`|`false`|Set to true if you wish not to show the error code when the last command returned an error and optionally hide this segment when the last command completed successfully by setting `POWERLEVEL9K_STATUS_OK` to false.| +|`POWERLEVEL9K_STATUS_OK`|`true`|Set to true if you wish to show this segment when the last command completed successfully, false to hide it.| +|`POWERLEVEL9K_STATUS_SHOW_PIPESTATUS`|`true`|Set to true if you wish to show the exit status for all piped commands.| +|`POWERLEVEL9K_STATUS_HIDE_SIGNAME`|`false`|Set to true return the raw exit code (`1-255`). When set to false, values over 128 are shown as `SIGNAME(-n)` (e.g. `KILL(-9)`)| + +##### ram + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_RAM_ELEMENTS`|Both|Specify `ram_free` or `swap_used` to only show one or the other rather than both.| + +##### symfony2_tests + +See [Unit Test Ratios](#unit-test-ratios), below. + +##### time + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_TIME_FORMAT`|`'H:M:S'`|ZSH time format to use in this segment.| + +As an example, if you wanted a reversed time format, you would use this: +```zsh +# Reversed time format +POWERLEVEL9K_TIME_FORMAT='%D{%S:%M:%H}' +``` +If you are using an "Awesome Powerline Font", you can add a time symbol to this +segment, as well: +```zsh +# Output time, date, and a symbol from the "Awesome Powerline Font" set +POWERLEVEL9K_TIME_FORMAT="%D{%H:%M:%S \uE868 %d.%m.%y}" +``` +##### user + +The `user` segment will print the username. + +You can also override the icons by setting: + +``` +POWERLEVEL9K_USER_ICON="\uF415" #  +POWERLEVEL9K_ROOT_ICON="#" +POWERLEVEL9K_SUDO_ICON=$'\uF09C' #  +``` + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`DEFAULT_USER`|None|Username to consider a "default context".| +|`POWERLEVEL9K_ALWAYS_SHOW_USER`|`false`|Always print this segment.| +|`POWERLEVEL9K_USER_TEMPLATE`|`%n`|Default username prompt. Refer to the [ZSH Documentation](http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html) for all possible expansions| + +##### vcs + +By default, the `vcs` segment will provide quite a bit of information. Further +customization is provided via: + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_HIDE_BRANCH_ICON`|`false`|Set to `true` to hide the branch icon from the segment.| +|`POWERLEVEL9K_SHOW_CHANGESET`|`false`|Set to `true` to display the hash / changeset in the segment.| +|`POWERLEVEL9K_CHANGESET_HASH_LENGTH`|`12`|How many characters of the hash / changeset to display in the segment.| +|`POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY`|`true`|Set to `false` to not reflect submodule status in the top-level repository prompt.| +|`POWERLEVEL9K_VCS_HIDE_TAGS`|`false`|Set to `true` to stop tags being displayed in the segment.| +|`POWERLEVEL9K_VCS_GIT_HOOKS`|`(vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname)`|Layout of the segment for git repositories.| +|`POWERLEVEL9K_VCS_HG_HOOKS`|`(vcs-detect-changes)`|Layout of the segment for Mercurial repositories.| +|`POWERLEVEL9K_VCS_SVN_HOOKS`|`(vcs-detect-changes svn-detect-changes)`|Layout of the segment for SVN repositories.| +|`POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND`|`red`|The color of the foreground font during actions (e.g., `REBASE`).| + + +##### vcs symbols + +The `vcs` segment uses various symbols to tell you the state of your repository. +These symbols depend on your installed font and selected `POWERLEVEL9K_MODE` +from the [Installation](#Installation) section above. + +| `Compatible` | `Powerline` | `Awesome Powerline` | Explanation +|--------------|---------------------|-------------------|-------------------------- +| `↑4` | `↑4` | ![icon_outgoing](https://cloud.githubusercontent.com/assets/1544760/7976089/b5904d6e-0a76-11e5-8147-5e873ac52d79.gif)4 | Number of commits your repository is ahead of your remote branch +| `↓5` | `↓5` | ![icon_incoming](https://cloud.githubusercontent.com/assets/1544760/7976091/b5909c9c-0a76-11e5-9cad-9bf0a28a897c.gif)5 | Number of commits your repository is behind of your remote branch +| `⍟3` | `⍟3` | ![icon_stash](https://cloud.githubusercontent.com/assets/1544760/7976094/b5ae9346-0a76-11e5-8cc7-e98b81824118.gif)3 | Number of stashes, here 3. +| `●` | `●` | ![icon_unstaged](https://cloud.githubusercontent.com/assets/1544760/7976096/b5aefa98-0a76-11e5-9408-985440471215.gif) | There are unstaged changes in your working copy +| `✚` | `✚` | ![icon_staged](https://cloud.githubusercontent.com/assets/1544760/7976095/b5aecc8a-0a76-11e5-8988-221afc6e8982.gif) | There are staged changes in your working copy +| `?` | `?` | ![icon_untracked](https://cloud.githubusercontent.com/assets/1544760/7976098/b5c7a2e6-0a76-11e5-8c5b-315b595b2bc4.gif) | There are files in your working copy, that are unknown to your repository +| `→` | `→` | ![icon_remote_tracking_branch](https://cloud.githubusercontent.com/assets/1544760/7976093/b5ad2c0e-0a76-11e5-9cd3-62a077b1b0c7.gif) | The name of your branch differs from its tracking branch. +| `☿` | `☿` | ![icon_bookmark](https://cloud.githubusercontent.com/assets/1544760/7976197/546cfac6-0a78-11e5-88a6-ce3a1e0a174e.gif) | A mercurial bookmark is active. +| `@` | ![icon_branch_powerline](https://cloud.githubusercontent.com/assets/1544760/8000852/e7e8d8a0-0b5f-11e5-9834-de9b25c92284.gif) | ![](https://cloud.githubusercontent.com/assets/1544760/7976087/b58bbe3e-0a76-11e5-8d0d-7a5c1bc7f730.gif) | Branch Icon +| None | None | ![icon_commit](https://cloud.githubusercontent.com/assets/1544760/7976088/b58f4e50-0a76-11e5-9e70-86450d937030.gif)2c3705 | The current commit hash. Here "2c3705" +| None | None | ![icon_git](https://cloud.githubusercontent.com/assets/1544760/7976092/b5909f80-0a76-11e5-9950-1438b9d72465.gif) | Repository is a git repository +| None | None | ![icon_mercurial](https://cloud.githubusercontent.com/assets/1544760/7976090/b5908da6-0a76-11e5-8c91-452b6e73f631.gif) | Repository is a Mercurial repository + +##### vcs truncation + +You can limit the branch name to a certain length by truncating long names. +Customizations available are: + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_VCS_SHORTEN_LENGTH`|None|This field determines how many characters to show.| +|`POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH`|None|This field determines minimum branch length. Branch name will be truncated if its length greater than this field.| +|`POWERLEVEL9K_VCS_SHORTEN_STRATEGY`|None|This field determines how branch name should be truncated. See the table below for more information.| +|`POWERLEVEL9K_SHORTEN_DELIMITER`|`...`|Delimiter to use in truncated strings. This can be any string you choose, including an empty string if you wish to have no delimiter.| + +| Strategy Name | Description | +|---------------|-------------| +|`truncate_middle`|Truncates the middle part of a branch. E.g. branch name is `1234-super_super_long_branch_name`, then it will truncated to `1234-..._name`, if `POWERLEVEL9K_VCS_SHORTEN_LENGTH=5` is also set (controls the amount of characters to be left).| +|`truncate_from_right`|Just leaves the beginning of a branch name untouched. E.g. branch name will be truncated like so: `1234-...`. How many characters will be untouched is controlled by `POWERLEVEL9K_VCS_SHORTEN_LENGTH`.| + +For example, if you want to truncate `1234-super_super_long_branch_name` to `1234-..` and don't do it with `development`: +```zsh +POWERLEVEL9K_VCS_SHORTEN_LENGTH=4 +POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=11 +POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right" +POWERLEVEL9K_VCS_SHORTEN_DELIMITER=".." +``` + +##### vi_mode + +This segment shows ZSH's current input mode. Note that this is only useful if +you are using the [ZSH Line Editor](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html) +(VI mode). You can enable this either by `.zshrc` configuration or using a plugin, like +[Oh-My-Zsh's vi-mode plugin](https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/vi-mode/vi-mode.plugin.zsh). + +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`POWERLEVEL9K_VI_INSERT_MODE_STRING`|`"INSERT"`|String to display while in 'Insert' mode.| +|`POWERLEVEL9K_VI_COMMAND_MODE_STRING`|`"NORMAL"`|String to display while in 'Command' mode.| + +To hide the segment entirely when in `INSERT` mode, set `POWERLEVEL9K_VI_INSERT_MODE_STRING=''` + +#### Unit Test Ratios + +The `symfony2_tests` and `rspec_stats` segments both show a ratio of "real" +classes vs test classes in your source code. This is just a very simple ratio, +and does not show your code coverage or any sophisticated stats. All this does +is count your source files and test files, and calculate the ratio between them. +Just enough to give you a quick overview about the test situation of the project +you are dealing with. + +### Disabling / Enabling Powerlevel9k + +You can disable P9k and return to a very basic prompt at any time simply by +calling: + +```zsh +$ prompt_powerlevel9k_teardown +``` + +You can then re-enable it by calling: + +```zsh +$ prompt_powerlevel9k_setup +``` + +### tl; dr + +Want to just get a quick start? Check out the [Show Off Your +Config](https://github.com/bhilburn/powerlevel9k/wiki/Show-Off-Your-Config) +portion of the wiki to get going. + +[The Wiki also has a ton of other useful +information!](https://github.com/bhilburn/powerlevel9k/wiki) + +### License + +Project: MIT + +Logo: CC-BY-SA. Source repository: https://github.com/bhilburn/powerlevel9k-logo diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/TESTS.md b/config/zsh/oh-my-zsh-custom/powerlevel9k/TESTS.md new file mode 100644 index 0000000..b57c4d6 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/TESTS.md @@ -0,0 +1,69 @@ +# Tests + +## Automated Tests + +The Unit-Tests do not follow exactly the file structure of Powerlevel9k itself, +but we try to reflect the structure as much as possible. All tests are located +under `test/`. Segment specific tests under `test/segments/` (one file per +segment). + +### Installation + +In order to execute the tests you need to install `shunit2`, which is a +submodule. To install the submodule, you can execute +`git submodule init && git submodule update`. + +### Executing tests + +The tests are shell scripts on their own. So you can execute them right away. +To execute all tests you could just execute `./test/suite.spec`. + +### General Test Structure + +The tests usually have a `setUp()` function which is executed before every +test function. Speaking of, test functions must be prefixed with `test`. In +the tests, you can do [different Assertions](https://github.com/kward/shunit2#-asserts). +It is always a good idea to mock the program you want to test (just have a +look at other tests), so that the testrunner does not have to have all +programs installed. + +### Travis + +We use [Travis](https://travis-ci.org/) for Continuous Integration. This +service executes our tests after every push. For now, we need to tell travis +where to find the tests, which is what happens in the `.travis.yml` file. + +## Manual Testing + +If unit tests are not sufficient (e.g. you have an issue with your prompt that +occurs only in a specific ZSH framework) then you can use either Docker or +or our Vagrant. + +### Docker + +This is the easiest to use _if_ you have Docker already installed and running. + +The command `./test-in-docker` should make it fairly easy to get into a running +container with the framework of your choice. + +Examples: + +``` zsh +# Test Antigen with the oldest version of ZSH +$ ./test-in-docker antigen +``` + +``` zsh +# Test Prezto with ZSH version 5.2 +$ ./test-in-docker --zsh 5.2 prezto +``` + +You can get Docker at . + +**Note:** Not all frameworks work with all versions of ZSH (or the underlying OS). + +### Vagrant + +Currently there are two test VMs. `test-vm` is an Ubuntu machine with several +pre-installed ZSH frameworks. And there is `test-bsd-vm` which is a FreeBSD! +For how to run the machines see [here](test-vm/README.md). diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/debug/font-issues.zsh b/config/zsh/oh-my-zsh-custom/powerlevel9k/debug/font-issues.zsh new file mode 100755 index 0000000..82f8e60 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/debug/font-issues.zsh @@ -0,0 +1,423 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +source functions/colors.zsh +source functions/icons.zsh +source functions/utilities.zsh +# Map our $OS to neofetch $os +os="$OS" + + +trim() { + set -f + # shellcheck disable=2048,2086 + set -- $* + printf '%s\n' "${*//[[:space:]]/}" + set +f +} + +get_ppid() { + # Get parent process ID of PID. + case "$os" in + "Windows") + ppid="$(ps -p "${1:-$PPID}" | awk '{printf $2}')" + ppid="${ppid/PPID}" + ;; + + "Linux") + ppid="$(grep -i -F "PPid:" "/proc/${1:-$PPID}/status")" + ppid="$(trim "${ppid/PPid:}")" + ;; + + *) + ppid="$(ps -p "${1:-$PPID}" -o ppid=)" + ;; + esac + + printf "%s" "$ppid" +} + +get_process_name() { + # Get PID name. + case "$os" in + "Windows") + name="$(ps -p "${1:-$PPID}" | awk '{printf $8}')" + name="${name/COMMAND}" + name="${name/*\/}" + ;; + + "Linux") + name="$(< "/proc/${1:-$PPID}/comm")" + ;; + + *) + name="$(ps -p "${1:-$PPID}" -o comm=)" + ;; + esac + + printf "%s" "$name" +} + +# Taken from NeoFetch (slightly modified) +get_term() { + local term + + # If function was run, stop here. + # ((term_run == 1)) && return + + # Workaround for macOS systems that + # don't support the block below. + case "$TERM_PROGRAM" in + "iTerm.app") term="iTerm2" ;; + "Terminal.app") term="Apple Terminal" ;; + "Hyper") term="HyperTerm" ;; + *) term="${TERM_PROGRAM/\.app}" ;; + esac + + # Most likely TosWin2 on FreeMiNT - quick check + [[ "$TERM" == "tw52" || "$TERM" == "tw100" ]] && \ + term="TosWin2" + + [[ "$SSH_CONNECTION" ]] && \ + term="$SSH_TTY" + + # Check $PPID for terminal emulator. + while [[ -z "$term" ]]; do + parent="$(get_ppid "$parent")" + [[ -z "$parent" ]] && break + name="$(get_process_name "$parent")" + + case "${name// }" in + "${SHELL/*\/}"|*"sh"|"screen"|"su"*) ;; + + "login"*|*"Login"*|"init"|"(init)") + term="$(tty)" + ;; + + "ruby"|"1"|"tmux"*|"systemd"|"sshd"*|"python"*|"USER"*"PID"*|"kdeinit"*|"launchd"*) + break + ;; + + "gnome-terminal-") term="gnome-terminal" ;; + "urxvtd") term="urxvt" ;; + *"nvim") term="Neovim Terminal" ;; + *"NeoVimServer"*) term="VimR Terminal" ;; + *) term="${name##*/}" ;; + esac + done + + # Log that the function was run. + # term_run=1 + + echo "${term}" +} + +get_term_font() { + local term="${1}" + # ((term_run != 1)) && get_term + + case "$term" in + "alacritty"*) + shopt -s nullglob + confs=({$XDG_CONFIG_HOME,$HOME}/{alacritty,}/{.,}alacritty.ym?) + shopt -u nullglob + + [[ -f "${confs[0]}" ]] || return + + term_font="$(awk -F ':|#' '/normal:/ {getline; print}' "${confs[0]}")" + term_font="${term_font/*family:}" + term_font="${term_font/$'\n'*}" + term_font="${term_font/\#*}" + ;; + + "Apple_Terminal") + term_font="$(osascript </dev/null | grep -c "Guid") +for idx in $(seq 0 "${profilesCount}"); do + local profileName=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Name:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null) + if [[ "${profileName}" == "${currentProfileName}" ]]; then + # "Normal Font" + normalFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Normal\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) + type=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Terminal\ Type:" ~/Library/Preferences/com.googlecode.iterm2.plist) + command=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Command:" ~/Library/Preferences/com.googlecode.iterm2.plist) + ambiguousDoubleWidth=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Ambiguous\ Double\ Width:" ~/Library/Preferences/com.googlecode.iterm2.plist) + minimumContrast=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Minimum\ Contrast:" ~/Library/Preferences/com.googlecode.iterm2.plist) + + # Font for non-ascii characters + # Only check for a different non-ASCII font, if the user checked + # the "use a different font for non-ascii text" switch. + useDifferentFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Use\ Non-ASCII\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) + if [[ "$useDifferentFont" == "true" ]]; then + nonAsciiFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Non\ Ascii\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) + if [[ "$normalFont" != "$nonAsciiFont" ]]; then + normalFont="$normalFont (normal) / $nonAsciiFont (non-ascii)" + fi + fi + break + fi +done + +print -P "You use %F{blue}iTerm2%f with the following settings:" +print -P " Font: ${normalFont}" +print -P " Terminal-Type: ${type}" +print -P " Command: ${command}" + +############################# +# Analyse possible problems # +############################# +local problemsFound +if [[ "${ambiguousDoubleWidth}" == "true" ]]; then + problemsFound="${problemsFound}\n * Please uncheck 'Treat ambiguous characters as double-width'." +fi +if (( minimumContrast > 0 )); then + problemsFound="${problemsFound}\n * Please set minimum contrast to zero." +fi +if [[ $(echo "${normalFont}" | grep -c -E "Powerline|Awesome|Nerd|Source Code Pro") -eq 0 ]]; then + problemsFound="${problemsFound}\n * It does not seem like you use an Powerline-enabled or Awesome Terminal Font!" +fi + +############################# +# Output problems # +############################# +if [[ -n "${problemsFound}" ]]; then + print -P "\n" + print -P "%F{yellow}Possible Problems found:%f" + print -P "${problemsFound}" +else + print -P "%F{green}No Problems found%f. Yay!" +fi diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antibody/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antibody/Dockerfile new file mode 100644 index 0000000..84a60a8 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antibody/Dockerfile @@ -0,0 +1,8 @@ +ARG base +FROM p9k:${base} + +COPY docker/antibody/install.zsh /tmp/ +RUN zsh /tmp/install.zsh + +COPY ./ p9k/ +COPY docker/antibody/zshrc .zshrc diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antibody/install.zsh b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antibody/install.zsh new file mode 100644 index 0000000..4c54fa6 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antibody/install.zsh @@ -0,0 +1 @@ +curl -sL https://git.io/antibody | bash -s diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antibody/zshrc b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antibody/zshrc new file mode 100644 index 0000000..d516b67 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antibody/zshrc @@ -0,0 +1,2 @@ +source <(antibody init) +antibody bundle ~/p9k/ diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antigen/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antigen/Dockerfile new file mode 100644 index 0000000..d8d0a4b --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antigen/Dockerfile @@ -0,0 +1,8 @@ +ARG base +FROM p9k:${base} + +COPY docker/antigen/install.zsh /tmp/ +RUN zsh /tmp/install.zsh + +COPY ./ p9k/ +COPY docker/antigen/zshrc .zshrc diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antigen/install.zsh b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antigen/install.zsh new file mode 100644 index 0000000..6bab8ab --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antigen/install.zsh @@ -0,0 +1,12 @@ +#!/bin/zsh + +mkdir ~/antigen + +curl \ + -qLsSf \ + -o ~/antigen/antigen.zsh \ + https://git.io/antigen + +source ~/antigen/antigen.zsh + +# EOF diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antigen/zshrc b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antigen/zshrc new file mode 100644 index 0000000..0f8d4da --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/antigen/zshrc @@ -0,0 +1,4 @@ +source ~/antigen/antigen.zsh + +antigen theme "${HOME}/p9k" powerlevel9k --no-local-clone +antigen apply diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-4.3.11/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-4.3.11/Dockerfile new file mode 100644 index 0000000..805a7ae --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-4.3.11/Dockerfile @@ -0,0 +1,31 @@ +FROM centos:6 + +RUN \ + yum install -y \ + curl \ + git \ + zsh \ + mercurial \ + subversion \ + golang \ + jq \ + node \ + ruby \ + python \ + python-virtualenv \ + sudo + +RUN adduser --shell /bin/zsh --comment 'fred' --user-group fred + +COPY docker/fred-sudoers /etc/sudoers.d/fred + +USER fred +WORKDIR /home/fred +ENV LANG=en_US.UTF-8 +ENV TERM=xterm-256color +ENV DEFAULT_USER=fred +ENV POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true + +RUN touch .zshrc + +CMD ["/bin/zsh", "-l"] diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.0.3/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.0.3/Dockerfile new file mode 100644 index 0000000..b1b85fc --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.0.3/Dockerfile @@ -0,0 +1,33 @@ +FROM ubuntu:14.04 + +RUN \ + apt-get update && \ + echo 'golang-go golang-go/dashboard boolean false' | debconf-set-selections && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + curl \ + git \ + zsh=5.0.2-3ubuntu6.2 \ + mercurial \ + subversion \ + golang \ + jq \ + node \ + ruby \ + python \ + python-virtualenv + +RUN adduser --shell /bin/zsh --gecos 'fred' --disabled-password fred +RUN locale-gen "en_US.UTF-8" + +COPY docker/fred-sudoers /etc/sudoers.d/fred + +USER fred +WORKDIR /home/fred +ENV LANG=en_US.UTF-8 +ENV TERM=xterm-256color +ENV DEFAULT_USER=fred +ENV POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true + +RUN touch .zshrc + +CMD ["/bin/zsh", "-l"] diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.1.1/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.1.1/Dockerfile new file mode 100644 index 0000000..c4fb642 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.1.1/Dockerfile @@ -0,0 +1,35 @@ +FROM ubuntu:16.04 + +RUN \ + apt-get update && \ + echo 'golang-go golang-go/dashboard boolean false' | debconf-set-selections && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + curl \ + git \ + zsh=5.1.1-1ubuntu2.2 \ + mercurial \ + subversion \ + golang \ + jq \ + nodejs \ + ruby \ + python \ + python-virtualenv \ + sudo \ + locales + +RUN adduser --shell /bin/zsh --gecos 'fred' --disabled-password fred +RUN locale-gen "en_US.UTF-8" + +COPY docker/fred-sudoers /etc/sudoers.d/fred + +USER fred +WORKDIR /home/fred +ENV LANG=en_US.UTF-8 +ENV TERM=xterm-256color +ENV DEFAULT_USER=fred +ENV POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true + +RUN touch .zshrc + +CMD ["/bin/zsh", "-l"] diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.2/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.2/Dockerfile new file mode 100644 index 0000000..2ec096f --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.2/Dockerfile @@ -0,0 +1,35 @@ +FROM ubuntu:17.10 + +RUN \ + apt-get update && \ + echo 'golang-go golang-go/dashboard boolean false' | debconf-set-selections && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + curl \ + git \ + zsh=5.2-5ubuntu1.2 \ + mercurial \ + subversion \ + golang \ + jq \ + nodejs \ + ruby \ + python \ + python-virtualenv \ + sudo \ + locales + +RUN adduser --shell /bin/zsh --gecos 'fred' --disabled-password fred +RUN locale-gen "en_US.UTF-8" + +COPY docker/fred-sudoers /etc/sudoers.d/fred + +USER fred +WORKDIR /home/fred +ENV LANG=en_US.UTF-8 +ENV TERM=xterm-256color +ENV DEFAULT_USER=fred +ENV POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true + +RUN touch .zshrc + +CMD ["/bin/zsh", "-l"] diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.3.1/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.3.1/Dockerfile new file mode 100644 index 0000000..0294cf2 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.3.1/Dockerfile @@ -0,0 +1,40 @@ +FROM debian:stretch + +# We switched here to debian, as there seems no ZSH 5.3 in ubuntu. + +RUN \ + apt-get update && \ + echo 'golang-go golang-go/dashboard boolean false' | debconf-set-selections && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + curl \ + git \ + zsh=5.3.1-4+b2 \ + mercurial \ + subversion \ + golang \ + jq \ + nodejs \ + ruby \ + python \ + python-virtualenv \ + sudo \ + locales + +RUN adduser --shell /bin/zsh --gecos 'fred' --disabled-password fred +# Locale generation is different in debian. We need to enable en_US +# locale and then regenerate locales. +RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen +RUN locale-gen "en_US.UTF-8" + +COPY docker/fred-sudoers /etc/sudoers.d/fred + +USER fred +WORKDIR /home/fred +ENV LANG=en_US.UTF-8 +ENV TERM=xterm-256color +ENV DEFAULT_USER=fred +ENV POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true + +RUN touch .zshrc + +CMD ["/bin/zsh", "-l"] diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.4.2/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.4.2/Dockerfile new file mode 100644 index 0000000..8984c10 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.4.2/Dockerfile @@ -0,0 +1,35 @@ +FROM ubuntu:18.04 + +RUN \ + apt-get update && \ + echo 'golang-go golang-go/dashboard boolean false' | debconf-set-selections && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + curl \ + git \ + zsh=5.4.2-3ubuntu3 \ + mercurial \ + subversion \ + golang \ + jq \ + nodejs \ + ruby \ + python \ + python-virtualenv \ + sudo \ + locales + +RUN adduser --shell /bin/zsh --gecos 'fred' --disabled-password fred +RUN locale-gen "en_US.UTF-8" + +COPY docker/fred-sudoers /etc/sudoers.d/fred + +USER fred +WORKDIR /home/fred +ENV LANG=en_US.UTF-8 +ENV TERM=xterm-256color +ENV DEFAULT_USER=fred +ENV POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true + +RUN touch .zshrc + +CMD ["/bin/zsh", "-l"] diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.5.1/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.5.1/Dockerfile new file mode 100644 index 0000000..85fc570 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/base-5.5.1/Dockerfile @@ -0,0 +1,35 @@ +FROM ubuntu:18.10 + +RUN \ + apt-get update && \ + echo 'golang-go golang-go/dashboard boolean false' | debconf-set-selections && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + curl \ + git \ + zsh=5.5.1-1ubuntu1 \ + mercurial \ + subversion \ + golang \ + jq \ + nodejs \ + ruby \ + python \ + python-virtualenv \ + sudo \ + locales + +RUN adduser --shell /bin/zsh --gecos 'fred' --disabled-password fred +RUN locale-gen "en_US.UTF-8" + +COPY docker/fred-sudoers /etc/sudoers.d/fred + +USER fred +WORKDIR /home/fred +ENV LANG=en_US.UTF-8 +ENV TERM=xterm-256color +ENV DEFAULT_USER=fred +ENV POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true + +RUN touch .zshrc + +CMD ["/bin/zsh", "-l"] diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/dotfile/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/dotfile/Dockerfile new file mode 100644 index 0000000..f29c4d5 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/dotfile/Dockerfile @@ -0,0 +1,5 @@ +ARG base +FROM p9k:${base} + +COPY ./ p9k/ +COPY docker/dotfile/zshrc .zshrc diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/dotfile/zshrc b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/dotfile/zshrc new file mode 100644 index 0000000..382b84a --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/dotfile/zshrc @@ -0,0 +1 @@ +source "${HOME}/p9k/prompt_powerlevel9k_setup" diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/fred-sudoers b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/fred-sudoers new file mode 100644 index 0000000..5fcd646 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/fred-sudoers @@ -0,0 +1,2 @@ +Defaults:fred !requiretty +fred ALL=(ALL) NOPASSWD: ALL diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/omz/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/omz/Dockerfile new file mode 100644 index 0000000..1a417b9 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/omz/Dockerfile @@ -0,0 +1,8 @@ +ARG base +FROM p9k:${base} + +COPY docker/omz/install.zsh /tmp/ +RUN zsh /tmp/install.zsh + +COPY docker/omz/zshrc .zshrc +COPY ./ p9k/ diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/omz/install.zsh b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/omz/install.zsh new file mode 100644 index 0000000..e2cdfa9 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/omz/install.zsh @@ -0,0 +1,4 @@ +sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" + +mkdir -p ~/.oh-my-zsh/custom/themes +ln -nsf ~/p9k/ ~/.oh-my-zsh/custom/themes/powerlevel9k diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/omz/zshrc b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/omz/zshrc new file mode 100644 index 0000000..9e798e2 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/omz/zshrc @@ -0,0 +1,5 @@ +export ZSH=$HOME/.oh-my-zsh +ZSH_THEME="powerlevel9k/powerlevel9k" +plugins=(git rake ruby) + +source $ZSH/oh-my-zsh.sh diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/prezto/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/prezto/Dockerfile new file mode 100644 index 0000000..70f3b65 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/prezto/Dockerfile @@ -0,0 +1,7 @@ +ARG base +FROM p9k:${base} + +COPY docker/prezto/install.zsh /tmp/ +RUN zsh /tmp/install.zsh + +COPY ./ p9k/ diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/prezto/install.zsh b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/prezto/install.zsh new file mode 100644 index 0000000..2b2e878 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/prezto/install.zsh @@ -0,0 +1,18 @@ +#!/bin/zsh + +set -eu + +git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto" + +setopt EXTENDED_GLOB +for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do + ln -nsf "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}" +done + +ln -snf "${HOME}/p9k/powerlevel9k.zsh-theme" \ + "${HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup" + +echo "zstyle ':prezto:module:prompt' theme 'powerlevel9k'" \ + >> "${HOME}/.zpreztorc" + +# EOF diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zgen/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zgen/Dockerfile new file mode 100644 index 0000000..48e44c7 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zgen/Dockerfile @@ -0,0 +1,8 @@ +ARG base +FROM p9k:${base} + +COPY docker/zgen/install.zsh /tmp/ +RUN zsh /tmp/install.zsh + +COPY ./ p9k/ +COPY docker/zgen/zshrc .zshrc diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zgen/install.zsh b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zgen/install.zsh new file mode 100644 index 0000000..5cdc618 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zgen/install.zsh @@ -0,0 +1,5 @@ +#!/bin/zsh + +git clone https://github.com/tarjoilija/zgen.git "${HOME}/.zgen" + +# EOF diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zgen/zshrc b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zgen/zshrc new file mode 100644 index 0000000..1fcb75b --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zgen/zshrc @@ -0,0 +1,10 @@ +# load zgen +source ~/.zgen/zgen.zsh + +# if the init scipt doesn't exist +if ! zgen saved; then + zgen load ~/p9k/powerlevel9k.zsh-theme + + # generate the init script from plugins above + zgen save +fi diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zim/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zim/Dockerfile new file mode 100644 index 0000000..cfe0fc9 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zim/Dockerfile @@ -0,0 +1,7 @@ +ARG base +FROM p9k:${base} + +COPY docker/zim/install.zsh /tmp/ +RUN zsh /tmp/install.zsh + +COPY ./ p9k/ diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zim/install.zsh b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zim/install.zsh new file mode 100644 index 0000000..d6c6006 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zim/install.zsh @@ -0,0 +1,21 @@ +#!zsh + +git clone --recursive https://github.com/Eriner/zim.git "${ZDOTDIR:-${HOME}}/.zim" + +setopt EXTENDED_GLOB +for template_file ( ${ZDOTDIR:-${HOME}}/.zim/templates/* ); do + user_file="${ZDOTDIR:-${HOME}}/.${template_file:t}" + touch ${user_file} + ( print -rn "$(<${template_file})$(<${user_file})" >! ${user_file} ) 2>/dev/null +done + +source "${ZDOTDIR:-${HOME}}/.zlogin" + +ln -nsf \ + ~/p9k/ \ + ~/.zim/modules/prompt/external-themes/powerlevel9k +ln -nsf \ + ~/.zim/modules/prompt/external-themes/powerlevel9k/powerlevel9k.zsh-theme \ + ~/.zim/modules/prompt/functions/prompt_powerlevel9k_setup + +sed -i "s/zprompt_theme='steeef'/zprompt_theme='powerlevel9k'/g" ~/.zimrc diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplug/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplug/Dockerfile new file mode 100644 index 0000000..89c23d5 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplug/Dockerfile @@ -0,0 +1,8 @@ +ARG base +FROM p9k:${base} + +COPY docker/zplug/install.zsh /tmp/ +RUN zsh /tmp/install.zsh + +COPY ./ p9k/ +COPY docker/zplug/zshrc .zshrc diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplug/install.zsh b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplug/install.zsh new file mode 100644 index 0000000..b01ff6e --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplug/install.zsh @@ -0,0 +1,5 @@ +#!zsh + +curl -sL --proto-redir -all,https https://raw.githubusercontent.com/zplug/installer/master/installer.zsh| zsh + +# git clone https://github.com/zplug/zplug "${HOME}/.zplug" diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplug/zshrc b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplug/zshrc new file mode 100644 index 0000000..0a4ceb8 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplug/zshrc @@ -0,0 +1,5 @@ +#!zsh + +source ~/.zplug/init.zsh +zplug "${HOME}/p9k", use:"powerlevel9k.zsh-theme", from:local, as:theme +zplug load --verbose diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplugin/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplugin/Dockerfile new file mode 100644 index 0000000..90c35c0 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplugin/Dockerfile @@ -0,0 +1,8 @@ +ARG base +FROM p9k:${base} + +COPY docker/zplugin/install.zsh /tmp/ +RUN zsh /tmp/install.zsh + +COPY ./ p9k/ +COPY docker/zplugin/zshrc.plugins .zshrc.plugins diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplugin/install.zsh b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplugin/install.zsh new file mode 100644 index 0000000..fec4249 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplugin/install.zsh @@ -0,0 +1,12 @@ +sh -c "$(curl -fsSL https://raw.githubusercontent.com/psprint/zplugin/master/doc/install.sh)" + +# The 'zplugin snippet' only copies the .zsh-theme file, not everything else. +mkdir -p ~/.zplugin/snippets +ln -nsf \ + ~/p9k/ \ +~/.zplugin/snippets/--SLASH--home--SLASH--fred--SLASH--p9k--SLASH--powerlevel9k--DOT--zsh-theme + +{ + echo + echo "source ~/.zshrc.plugins" +} >> ~/.zshrc diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplugin/zshrc.plugins b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplugin/zshrc.plugins new file mode 100644 index 0000000..2e9ba7a --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zplugin/zshrc.plugins @@ -0,0 +1,5 @@ +#!zsh + +zplugin load psprint zsh-navigation-tools +zplugin load psprint---zprompts +zplugin snippet ~/p9k/powerlevel9k.zsh-theme diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zpm/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zpm/Dockerfile new file mode 100644 index 0000000..c1c44e3 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zpm/Dockerfile @@ -0,0 +1,8 @@ +ARG base +FROM p9k:${base} + +COPY docker/zpm/install.zsh /tmp/ +RUN zsh /tmp/install.zsh + +COPY ./ p9k/ +COPY docker/zpm/zshrc .zshrc diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zpm/install.zsh b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zpm/install.zsh new file mode 100644 index 0000000..6f74e8e --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zpm/install.zsh @@ -0,0 +1,6 @@ +# install zpm +git clone --recursive https://github.com/zpm-zsh/zpm.git ~/.zpm + +# Install powerlevel9k +mkdir ~/.zpm/plugins/powerlevel9k +ln -s ~/p9k/powerlevel9k.zsh-theme ~/.zpm/plugins/powerlevel9k/powerlevel9k.plugin.zsh diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zpm/zshrc b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zpm/zshrc new file mode 100644 index 0000000..b107976 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zpm/zshrc @@ -0,0 +1,3 @@ +source ~/.zpm/zpm.zsh + +zpm load powerlevel9k diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zshing/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zshing/Dockerfile new file mode 100644 index 0000000..a51a306 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zshing/Dockerfile @@ -0,0 +1,7 @@ +ARG base +FROM p9k:${base} + +COPY docker/zshing/install.zsh /tmp/ +RUN zsh /tmp/install.zsh + +COPY ./ p9k/ diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zshing/install.zsh b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zshing/install.zsh new file mode 100644 index 0000000..8f92699 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zshing/install.zsh @@ -0,0 +1,16 @@ +#!zsh + +# install zshing https://github.com/zakariaGatter/zshing +git clone https://github.com/zakariaGatter/zshing.git ~/.zshing/zshing + +# Link P9K in zshing directory +ln -nsf ~/p9k ~/.zshing/powerlevel9k + +{ + echo + echo 'ZSHING_PLUGINS=( + "bhilburn/powerlevel9k" + )' + echo + echo "source ~/.zshing/zshing/zshing.zsh" +} >> ~/.zshrc diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zulu/Dockerfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zulu/Dockerfile new file mode 100644 index 0000000..880a07d --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zulu/Dockerfile @@ -0,0 +1,7 @@ +ARG base +FROM p9k:${base} + +COPY docker/zulu/install.zsh /tmp/ +RUN zsh /tmp/install.zsh + +COPY ./ p9k/ diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zulu/install.zsh b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zulu/install.zsh new file mode 100644 index 0000000..0ad6aae --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/docker/zulu/install.zsh @@ -0,0 +1,10 @@ +#!zsh + +# install zulu https://github.com/zulu-zsh/zulu +curl -L https://git.io/zulu-install | zsh && zsh + +{ +echo 'zulu fpath add ~/p9k' +echo 'zulu fpath add ~/p9k/functions' +echo 'zulu theme powerlevel9k' +} >> ~/.zshrc diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/functions/colors.zsh b/config/zsh/oh-my-zsh-custom/powerlevel9k/functions/colors.zsh new file mode 100755 index 0000000..80abb6b --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/functions/colors.zsh @@ -0,0 +1,358 @@ +# vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 +################################################################ +# Color functions +# This file holds some color-functions for +# the powerlevel9k-ZSH-theme +# https://github.com/bhilburn/powerlevel9k +################################################################ + +typeset -gAh __P9K_COLORS +# https://jonasjacek.github.io/colors/ +# use color names by default to allow dark/light themes to adjust colors based on names +__P9K_COLORS=( + black 000 + red 001 + green 002 + yellow 003 + blue 004 + magenta 005 + cyan 006 + white 007 + grey 008 + maroon 009 + lime 010 + olive 011 + navy 012 + fuchsia 013 + purple 013 + aqua 014 + teal 014 + silver 015 + grey0 016 + navyblue 017 + darkblue 018 + blue3 019 + blue3 020 + blue1 021 + darkgreen 022 + deepskyblue4 023 + deepskyblue4 024 + deepskyblue4 025 + dodgerblue3 026 + dodgerblue2 027 + green4 028 + springgreen4 029 + turquoise4 030 + deepskyblue3 031 + deepskyblue3 032 + dodgerblue1 033 + green3 034 + springgreen3 035 + darkcyan 036 + lightseagreen 037 + deepskyblue2 038 + deepskyblue1 039 + green3 040 + springgreen3 041 + springgreen2 042 + cyan3 043 + darkturquoise 044 + turquoise2 045 + green1 046 + springgreen2 047 + springgreen1 048 + mediumspringgreen 049 + cyan2 050 + cyan1 051 + darkred 052 + deeppink4 053 + purple4 054 + purple4 055 + purple3 056 + blueviolet 057 + orange4 058 + grey37 059 + mediumpurple4 060 + slateblue3 061 + slateblue3 062 + royalblue1 063 + chartreuse4 064 + darkseagreen4 065 + paleturquoise4 066 + steelblue 067 + steelblue3 068 + cornflowerblue 069 + chartreuse3 070 + darkseagreen4 071 + cadetblue 072 + cadetblue 073 + skyblue3 074 + steelblue1 075 + chartreuse3 076 + palegreen3 077 + seagreen3 078 + aquamarine3 079 + mediumturquoise 080 + steelblue1 081 + chartreuse2 082 + seagreen2 083 + seagreen1 084 + seagreen1 085 + aquamarine1 086 + darkslategray2 087 + darkred 088 + deeppink4 089 + darkmagenta 090 + darkmagenta 091 + darkviolet 092 + purple 093 + orange4 094 + lightpink4 095 + plum4 096 + mediumpurple3 097 + mediumpurple3 098 + slateblue1 099 + yellow4 100 + wheat4 101 + grey53 102 + lightslategrey 103 + mediumpurple 104 + lightslateblue 105 + yellow4 106 + darkolivegreen3 107 + darkseagreen 108 + lightskyblue3 109 + lightskyblue3 110 + skyblue2 111 + chartreuse2 112 + darkolivegreen3 113 + palegreen3 114 + darkseagreen3 115 + darkslategray3 116 + skyblue1 117 + chartreuse1 118 + lightgreen 119 + lightgreen 120 + palegreen1 121 + aquamarine1 122 + darkslategray1 123 + red3 124 + deeppink4 125 + mediumvioletred 126 + magenta3 127 + darkviolet 128 + purple 129 + darkorange3 130 + indianred 131 + hotpink3 132 + mediumorchid3 133 + mediumorchid 134 + mediumpurple2 135 + darkgoldenrod 136 + lightsalmon3 137 + rosybrown 138 + grey63 139 + mediumpurple2 140 + mediumpurple1 141 + gold3 142 + darkkhaki 143 + navajowhite3 144 + grey69 145 + lightsteelblue3 146 + lightsteelblue 147 + yellow3 148 + darkolivegreen3 149 + darkseagreen3 150 + darkseagreen2 151 + lightcyan3 152 + lightskyblue1 153 + greenyellow 154 + darkolivegreen2 155 + palegreen1 156 + darkseagreen2 157 + darkseagreen1 158 + paleturquoise1 159 + red3 160 + deeppink3 161 + deeppink3 162 + magenta3 163 + magenta3 164 + magenta2 165 + darkorange3 166 + indianred 167 + hotpink3 168 + hotpink2 169 + orchid 170 + mediumorchid1 171 + orange3 172 + lightsalmon3 173 + lightpink3 174 + pink3 175 + plum3 176 + violet 177 + gold3 178 + lightgoldenrod3 179 + tan 180 + mistyrose3 181 + thistle3 182 + plum2 183 + yellow3 184 + khaki3 185 + lightgoldenrod2 186 + lightyellow3 187 + grey84 188 + lightsteelblue1 189 + yellow2 190 + darkolivegreen1 191 + darkolivegreen1 192 + darkseagreen1 193 + honeydew2 194 + lightcyan1 195 + red1 196 + deeppink2 197 + deeppink1 198 + deeppink1 199 + magenta2 200 + magenta1 201 + orangered1 202 + indianred1 203 + indianred1 204 + hotpink 205 + hotpink 206 + mediumorchid1 207 + darkorange 208 + salmon1 209 + lightcoral 210 + palevioletred1 211 + orchid2 212 + orchid1 213 + orange1 214 + sandybrown 215 + lightsalmon1 216 + lightpink1 217 + pink1 218 + plum1 219 + gold1 220 + lightgoldenrod2 221 + lightgoldenrod2 222 + navajowhite1 223 + mistyrose1 224 + thistle1 225 + yellow1 226 + lightgoldenrod1 227 + khaki1 228 + wheat1 229 + cornsilk1 230 + grey100 231 + grey3 232 + grey7 233 + grey11 234 + grey15 235 + grey19 236 + grey23 237 + grey27 238 + grey30 239 + grey35 240 + grey39 241 + grey42 242 + grey46 243 + grey50 244 + grey54 245 + grey58 246 + grey62 247 + grey66 248 + grey70 249 + grey74 250 + grey78 251 + grey82 252 + grey85 253 + grey89 254 + grey93 255 +) + +function termColors() { + if [[ $POWERLEVEL9K_IGNORE_TERM_COLORS == true ]]; then + return + fi + + local term_colors + + if which tput &>/dev/null; then + term_colors=$(tput colors) + else + term_colors=$(echotc Co) + fi + if (( ! $? && ${term_colors:-0} < 256 )); then + print -P "%F{red}WARNING!%f Your terminal appears to support fewer than 256 colors!" + print -P "If your terminal supports 256 colors, please export the appropriate environment variable" + print -P "_before_ loading this theme in your \~\/.zshrc. In most terminal emulators, putting" + print -P "%F{blue}export TERM=\"xterm-256color\"%f at the top of your \~\/.zshrc is sufficient." + fi +} + +# get the proper color code if it does not exist as a name. +function getColor() { + # If Color is not numerical, try to get the color code. + if [[ "$1" != <-> ]]; then + 1=$(getColorCode $1) + fi + echo -n "$1" +} + +# empty paramenter resets (stops) background color +function backgroundColor() { + echo -n "%K{$(getColor $1)}" +} + +# empty paramenter resets (stops) foreground color +function foregroundColor() { + echo -n "%F{$(getColor $1)}" +} + +# Get numerical color codes. That way we translate ANSI codes +# into ZSH-Style color codes. +function getColorCode() { + # Early exit: Check if given value is already numerical + if [[ "$1" == <-> ]]; then + # Pad color with zeroes + echo -n "${(l:3::0:)1}" + return + fi + + local colorName="${1}" + # Check if value is none with any case. + if [[ "${(L)colorName}" == "none" ]]; then + echo -n 'none' + elif [[ "${colorName}" == "foreground" ]]; then + # for testing purposes in terminal + # call via `getColorCode foreground` + for i in "${(k@)__P9K_COLORS}"; do + print -P "$(foregroundColor $i)$(getColor $i) - $i%f" + done + elif [[ "${colorName}" == "background" ]]; then + # call via `getColorCode background` + for i in "${(k@)__P9K_COLORS}"; do + print -P "$(backgroundColor $i)$(getColor $i) - $i%k" + done + else + # Strip eventual "bg-" prefixes + colorName=${colorName#bg-} + # Strip eventual "fg-" prefixes + colorName=${colorName#fg-} + # Strip eventual "br" prefixes ("bright" colors) + colorName=${colorName#br} + echo -n $__P9K_COLORS[$colorName] + fi +} + +# Check if two colors are equal, even if one is specified as ANSI code. +function isSameColor() { + if [[ "$1" == "NONE" || "$2" == "NONE" ]]; then + return 1 + fi + + local color1=$(getColorCode "$1") + local color2=$(getColorCode "$2") + + return $(( color1 != color2 )) +} diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/functions/icons.zsh b/config/zsh/oh-my-zsh-custom/powerlevel9k/functions/icons.zsh new file mode 100755 index 0000000..d8661e6 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/functions/icons.zsh @@ -0,0 +1,560 @@ +# vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 +################################################################ +# icons +# This file holds the icon definitions and +# icon-functions for the powerlevel9k-ZSH-theme +# https://github.com/bhilburn/powerlevel9k +################################################################ + +# These characters require the Powerline fonts to work properly. If you see +# boxes or bizarre characters below, your fonts are not correctly installed. If +# you do not want to install a special font, you can set `POWERLEVEL9K_MODE` to +# `compatible`. This shows all icons in regular symbols. + +# Initialize the icon list according to the user's `POWERLEVEL9K_MODE`. +typeset -gAH icons +case $POWERLEVEL9K_MODE in + 'flat'|'awesome-patched') + # Awesome-Patched Font required! See: + # https://github.com/gabrielelana/awesome-terminal-fonts/tree/patching-strategy/patched + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" + icons=( + LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  + RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  + LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace + LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #  + RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  + CARRIAGE_RETURN_ICON $'\u21B5' # ↵ + ROOT_ICON $'\uE801' #  + SUDO_ICON $'\uF09C' #  + RUBY_ICON $'\uE847 ' #  + AWS_ICON $'\uE895' #  + AWS_EB_ICON $'\U1F331 ' # 🌱 + BACKGROUND_JOBS_ICON $'\uE82F ' #  + TEST_ICON $'\uE891' #  + TODO_ICON $'\u2611' # ☑ + BATTERY_ICON $'\uE894' #  + DISK_ICON $'\uE1AE ' #  + OK_ICON $'\u2714' # ✔ + FAIL_ICON $'\u2718' # ✘ + SYMFONY_ICON 'SF' + NODE_ICON $'\u2B22' # ⬢ + MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ + MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ + MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ + APPLE_ICON $'\uE26E' #  + WINDOWS_ICON $'\uE26F' #  + FREEBSD_ICON $'\U1F608 ' # 😈 + ANDROID_ICON $'\uE270' #  + LINUX_ICON $'\uE271' #  + LINUX_ARCH_ICON $'\uE271' #  + LINUX_DEBIAN_ICON $'\uE271' #  + LINUX_UBUNTU_ICON $'\uE271' #  + LINUX_CENTOS_ICON $'\uE271' #  + LINUX_COREOS_ICON $'\uE271' #  + LINUX_ELEMENTARY_ICON $'\uE271' #  + LINUX_MINT_ICON $'\uE271' #  + LINUX_FEDORA_ICON $'\uE271' #  + LINUX_GENTOO_ICON $'\uE271' #  + LINUX_MAGEIA_ICON $'\uE271' #  + LINUX_NIXOS_ICON $'\uE271' #  + LINUX_MANJARO_ICON $'\uE271' #  + LINUX_DEVUAN_ICON $'\uE271' #  + LINUX_ALPINE_ICON $'\uE271' #  + LINUX_AOSC_ICON $'\uE271' #  + LINUX_OPENSUSE_ICON $'\uE271' #  + LINUX_SABAYON_ICON $'\uE271' #  + LINUX_SLACKWARE_ICON $'\uE271' #  + SUNOS_ICON $'\U1F31E ' # 🌞 + HOME_ICON $'\uE12C' #  + HOME_SUB_ICON $'\uE18D' #  + FOLDER_ICON $'\uE818' #  + NETWORK_ICON $'\uE1AD' #  + ETC_ICON $'\uE82F' #  + LOAD_ICON $'\uE190 ' #  + SWAP_ICON $'\uE87D' #  + RAM_ICON $'\uE1E2 ' #  + SERVER_ICON $'\uE895' #  + VCS_UNTRACKED_ICON $'\uE16C' #  + VCS_UNSTAGED_ICON $'\uE17C' #  + VCS_STAGED_ICON $'\uE168' #  + VCS_STASH_ICON $'\uE133 ' #  + #VCS_INCOMING_CHANGES_ICON $'\uE1EB ' #  + #VCS_INCOMING_CHANGES_ICON $'\uE80D ' #  + VCS_INCOMING_CHANGES_ICON $'\uE131 ' #  + #VCS_OUTGOING_CHANGES_ICON $'\uE1EC ' #  + #VCS_OUTGOING_CHANGES_ICON $'\uE80E ' #  + VCS_OUTGOING_CHANGES_ICON $'\uE132 ' #  + VCS_TAG_ICON $'\uE817 ' #  + VCS_BOOKMARK_ICON $'\uE87B' #  + VCS_COMMIT_ICON $'\uE821 ' #  + VCS_BRANCH_ICON $'\uE220 ' #  + VCS_REMOTE_BRANCH_ICON $'\u2192' # → + VCS_GIT_ICON $'\uE20E ' #  + VCS_GIT_GITHUB_ICON $'\uE20E ' # + VCS_GIT_BITBUCKET_ICON $'\uE20E ' # + VCS_GIT_GITLAB_ICON $'\uE20E ' # + VCS_HG_ICON $'\uE1C3 ' #  + VCS_SVN_ICON '(svn) ' + RUST_ICON '(rust)' + PYTHON_ICON $'\ue63c' #  + SWIFT_ICON '' + GO_ICON '' + PUBLIC_IP_ICON '' + LOCK_ICON $'\UE138' #  + EXECUTION_TIME_ICON $'\UE89C' #  + SSH_ICON '(ssh)' + VPN_ICON '(vpn)' + KUBERNETES_ICON $'\U2388' # ⎈ + DROPBOX_ICON $'\UF16B' #  + DATE_ICON $'\uE184' #  + TIME_ICON $'\uE12E' #  + JAVA_ICON $'\U2615' # ☕︎ + LARAVEL_ICON '' + ) + ;; + 'awesome-fontconfig') + # fontconfig with awesome-font required! See + # https://github.com/gabrielelana/awesome-terminal-fonts + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" + icons=( + LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  + RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  + LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace + LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #  + RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  + CARRIAGE_RETURN_ICON $'\u21B5' # ↵ + ROOT_ICON $'\uF201' #  + SUDO_ICON $'\uF09C' #  + RUBY_ICON $'\uF219 ' #  + AWS_ICON $'\uF270' #  + AWS_EB_ICON $'\U1F331 ' # 🌱 + BACKGROUND_JOBS_ICON $'\uF013 ' #  + TEST_ICON $'\uF291' #  + TODO_ICON $'\u2611' # ☑ + BATTERY_ICON $'\U1F50B' # 🔋 + DISK_ICON $'\uF0A0 ' #  + OK_ICON $'\u2714' # ✔ + FAIL_ICON $'\u2718' # ✘ + SYMFONY_ICON 'SF' + NODE_ICON $'\u2B22' # ⬢ + MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ + MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ + MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ + APPLE_ICON $'\uF179' #  + WINDOWS_ICON $'\uF17A' #  + FREEBSD_ICON $'\U1F608 ' # 😈 + ANDROID_ICON $'\uE17B' #  + LINUX_ICON $'\uF17C' #  + LINUX_ARCH_ICON $'\uF17C' #  + LINUX_DEBIAN_ICON $'\uF17C' #  + LINUX_UBUNTU_ICON $'\uF17C' #  + LINUX_CENTOS_ICON $'\uF17C' #  + LINUX_COREOS_ICON $'\uF17C' #  + LINUX_ELEMENTARY_ICON $'\uF17C' #  + LINUX_MINT_ICON $'\uF17C' #  + LINUX_FEDORA_ICON $'\uF17C' #  + LINUX_GENTOO_ICON $'\uF17C' #  + LINUX_MAGEIA_ICON $'\uF17C' #  + LINUX_NIXOS_ICON $'\uF17C' #  + LINUX_MANJARO_ICON $'\uF17C' #  + LINUX_DEVUAN_ICON $'\uF17C' #  + LINUX_ALPINE_ICON $'\uF17C' #  + LINUX_AOSC_ICON $'\uF17C' #  + LINUX_OPENSUSE_ICON $'\uF17C' #  + LINUX_SABAYON_ICON $'\uF17C' #  + LINUX_SLACKWARE_ICON $'\uF17C' #  + SUNOS_ICON $'\uF185 ' #  + HOME_ICON $'\uF015' #  + HOME_SUB_ICON $'\uF07C' #  + FOLDER_ICON $'\uF115' #  + ETC_ICON $'\uF013 ' #  + NETWORK_ICON $'\uF09E' #  + LOAD_ICON $'\uF080 ' #  + SWAP_ICON $'\uF0E4' #  + RAM_ICON $'\uF0E4' #  + SERVER_ICON $'\uF233' #  + VCS_UNTRACKED_ICON $'\uF059' #  + VCS_UNSTAGED_ICON $'\uF06A' #  + VCS_STAGED_ICON $'\uF055' #  + VCS_STASH_ICON $'\uF01C ' #  + VCS_INCOMING_CHANGES_ICON $'\uF01A ' #  + VCS_OUTGOING_CHANGES_ICON $'\uF01B ' #  + VCS_TAG_ICON $'\uF217 ' #  + VCS_BOOKMARK_ICON $'\uF27B' #  + VCS_COMMIT_ICON $'\uF221 ' #  + VCS_BRANCH_ICON $'\uF126 ' #  + VCS_REMOTE_BRANCH_ICON $'\u2192' # → + VCS_GIT_ICON $'\uF1D3 ' #  + VCS_GIT_GITHUB_ICON $'\uF113 ' #  + VCS_GIT_BITBUCKET_ICON $'\uF171 ' #  + VCS_GIT_GITLAB_ICON $'\uF296 ' #  + VCS_HG_ICON $'\uF0C3 ' #  + VCS_SVN_ICON '(svn) ' + RUST_ICON $'\uE6A8' #  + PYTHON_ICON $'\ue63c' #  + SWIFT_ICON '' + GO_ICON '' + PUBLIC_IP_ICON '' + LOCK_ICON $'\UF023' #  + EXECUTION_TIME_ICON $'\uF253' + SSH_ICON '(ssh)' + VPN_ICON $'\uF023' + KUBERNETES_ICON $'\U2388' # ⎈ + DROPBOX_ICON $'\UF16B' #  + DATE_ICON $'\uF073 ' #  + TIME_ICON $'\uF017 ' #  + JAVA_ICON $'\U2615' # ☕︎ + LARAVEL_ICON '' + ) + ;; + 'awesome-mapped-fontconfig') + # mapped fontconfig with awesome-font required! See + # https://github.com/gabrielelana/awesome-terminal-fonts + # don't forget to source the font maps in your startup script + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" + + if [ -z "$AWESOME_GLYPHS_LOADED" ]; then + echo "Powerlevel9k warning: Awesome-Font mappings have not been loaded. + Source a font mapping in your shell config, per the Awesome-Font docs + (https://github.com/gabrielelana/awesome-terminal-fonts), + Or use a different Powerlevel9k font configuration."; + fi + + icons=( + LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  + RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  + LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace + LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #  + RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  + CARRIAGE_RETURN_ICON $'\u21B5' # ↵ + ROOT_ICON '\u'$CODEPOINT_OF_OCTICONS_ZAP #  + SUDO_ICON '\u'$CODEPOINT_OF_AWESOME_UNLOCK #  + RUBY_ICON '\u'$CODEPOINT_OF_OCTICONS_RUBY' ' #  + AWS_ICON '\u'$CODEPOINT_OF_AWESOME_SERVER #  + AWS_EB_ICON $'\U1F331 ' # 🌱 + BACKGROUND_JOBS_ICON '\u'$CODEPOINT_OF_AWESOME_COG' ' #  + TEST_ICON '\u'$CODEPOINT_OF_AWESOME_BUG #  + TODO_ICON '\u'$CODEPOINT_OF_AWESOME_CHECK_SQUARE_O #  + BATTERY_ICON '\U'$CODEPOINT_OF_AWESOME_BATTERY_FULL #  + DISK_ICON '\u'$CODEPOINT_OF_AWESOME_HDD_O' ' #  + OK_ICON '\u'$CODEPOINT_OF_AWESOME_CHECK #  + FAIL_ICON '\u'$CODEPOINT_OF_AWESOME_TIMES #  + SYMFONY_ICON 'SF' + NODE_ICON $'\u2B22' # ⬢ + MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ + MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ + APPLE_ICON '\u'$CODEPOINT_OF_AWESOME_APPLE #  + FREEBSD_ICON $'\U1F608 ' # 😈 + LINUX_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_ARCH_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_DEBIAN_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_UBUNTU_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_CENTOS_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_COREOS_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_ELEMENTARY_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_MINT_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_FEDORA_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_GENTOO_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_MAGEIA_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_NIXOS_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_MANJARO_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_DEVUAN_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_ALPINE_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_AOSC_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_OPENSUSE_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_SABAYON_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_SLACKWARE_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + SUNOS_ICON '\u'$CODEPOINT_OF_AWESOME_SUN_O' ' #  + HOME_ICON '\u'$CODEPOINT_OF_AWESOME_HOME #  + HOME_SUB_ICON '\u'$CODEPOINT_OF_AWESOME_FOLDER_OPEN #  + FOLDER_ICON '\u'$CODEPOINT_OF_AWESOME_FOLDER_O #  + ETC_ICON '\u'$CODEPOINT_OF_AWESOME_COG' ' #  + NETWORK_ICON '\u'$CODEPOINT_OF_AWESOME_RSS #  + LOAD_ICON '\u'$CODEPOINT_OF_AWESOME_BAR_CHART' ' #  + SWAP_ICON '\u'$CODEPOINT_OF_AWESOME_DASHBOARD #  + RAM_ICON '\u'$CODEPOINT_OF_AWESOME_DASHBOARD #  + SERVER_ICON '\u'$CODEPOINT_OF_AWESOME_SERVER #  + VCS_UNTRACKED_ICON '\u'$CODEPOINT_OF_AWESOME_QUESTION_CIRCLE #  + VCS_UNSTAGED_ICON '\u'$CODEPOINT_OF_AWESOME_EXCLAMATION_CIRCLE #  + VCS_STAGED_ICON '\u'$CODEPOINT_OF_AWESOME_PLUS_CIRCLE #  + VCS_STASH_ICON '\u'$CODEPOINT_OF_AWESOME_INBOX' ' #  + VCS_INCOMING_CHANGES_ICON '\u'$CODEPOINT_OF_AWESOME_ARROW_CIRCLE_DOWN' ' #  + VCS_OUTGOING_CHANGES_ICON '\u'$CODEPOINT_OF_AWESOME_ARROW_CIRCLE_UP' ' #  + VCS_TAG_ICON '\u'$CODEPOINT_OF_AWESOME_TAG' ' #  + VCS_BOOKMARK_ICON '\u'$CODEPOINT_OF_OCTICONS_BOOKMARK #  + VCS_COMMIT_ICON '\u'$CODEPOINT_OF_OCTICONS_GIT_COMMIT' ' #  + VCS_BRANCH_ICON '\u'$CODEPOINT_OF_OCTICONS_GIT_BRANCH' ' #  + VCS_REMOTE_BRANCH_ICON '\u'$CODEPOINT_OF_OCTICONS_REPO_PUSH #  + VCS_GIT_ICON '\u'$CODEPOINT_OF_AWESOME_GIT' ' #  + VCS_GIT_GITHUB_ICON '\u'$CODEPOINT_OF_AWESOME_GITHUB_ALT' ' #  + VCS_GIT_BITBUCKET_ICON '\u'$CODEPOINT_OF_AWESOME_BITBUCKET' ' #  + VCS_GIT_GITLAB_ICON '\u'$CODEPOINT_OF_AWESOME_GITLAB' ' #  + VCS_HG_ICON '\u'$CODEPOINT_OF_AWESOME_FLASK' ' #  + VCS_SVN_ICON '(svn) ' + RUST_ICON $'\uE6A8' #  + PYTHON_ICON $'\U1F40D' # 🐍 + SWIFT_ICON $'\uE655' #  + PUBLIC_IP_ICON '\u'$CODEPOINT_OF_AWESOME_GLOBE #  + LOCK_ICON '\u'$CODEPOINT_OF_AWESOME_LOCK #  + EXECUTION_TIME_ICON '\u'$CODEPOINT_OF_AWESOME_HOURGLASS_END #  + SSH_ICON '(ssh)' + VPN_ICON '\u'$CODEPOINT_OF_AWESOME_LOCK + KUBERNETES_ICON $'\U2388' # ⎈ + DROPBOX_ICON '\u'$CODEPOINT_OF_AWESOME_DROPBOX #  + DATE_ICON $'\uF073 ' #  + TIME_ICON $'\uF017 ' #  + JAVA_ICON $'\U2615' # ☕︎ + LARAVEL_ICON '' + ) + ;; + 'nerdfont-complete'|'nerdfont-fontconfig') + # nerd-font patched (complete) font required! See + # https://github.com/ryanoasis/nerd-fonts + # http://nerdfonts.com/#cheat-sheet + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" + icons=( + LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  + RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  + LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace + LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #  + RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  + CARRIAGE_RETURN_ICON $'\u21B5' # ↵ + ROOT_ICON $'\uE614 ' #  + SUDO_ICON $'\uF09C' #  + RUBY_ICON $'\uF219 ' #  + AWS_ICON $'\uF270' #  + AWS_EB_ICON $'\UF1BD ' #  + BACKGROUND_JOBS_ICON $'\uF013 ' #  + TEST_ICON $'\uF188' #  + TODO_ICON $'\uF133' #  + BATTERY_ICON $'\UF240 ' #  + DISK_ICON $'\uF0A0' #  + OK_ICON $'\uF00C' #  + FAIL_ICON $'\uF00D' #  + SYMFONY_ICON $'\uE757' #  + NODE_ICON $'\uE617 ' #  + MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ + MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ + MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ + APPLE_ICON $'\uF179' #  + WINDOWS_ICON $'\uF17A' #  + FREEBSD_ICON $'\UF30C ' #  + ANDROID_ICON $'\uF17B' #  + LINUX_ARCH_ICON $'\uF303' #  + LINUX_CENTOS_ICON $'\uF304' #  + LINUX_COREOS_ICON $'\uF305' #  + LINUX_DEBIAN_ICON $'\uF306' #  + LINUX_ELEMENTARY_ICON $'\uF309' #  + LINUX_FEDORA_ICON $'\uF30a' #  + LINUX_GENTOO_ICON $'\uF30d' #  + LINUX_MAGEIA_ICON $'\uF310' #  + LINUX_MINT_ICON $'\uF30e' #  + LINUX_NIXOS_ICON $'\uF313' #  + LINUX_MANJARO_ICON $'\uF312' #  + LINUX_DEVUAN_ICON $'\uF307' #  + LINUX_ALPINE_ICON $'\uF300' #  + LINUX_AOSC_ICON $'\uF301' #  + LINUX_OPENSUSE_ICON $'\uF314' #  + LINUX_SABAYON_ICON $'\uF317' #  + LINUX_SLACKWARE_ICON $'\uF319' #  + LINUX_UBUNTU_ICON $'\uF31b' #  + LINUX_ICON $'\uF17C' #  + SUNOS_ICON $'\uF185 ' #  + HOME_ICON $'\uF015' #  + HOME_SUB_ICON $'\uF07C' #  + FOLDER_ICON $'\uF115' #  + ETC_ICON $'\uF013' #  + NETWORK_ICON $'\uF1EB' #  + LOAD_ICON $'\uF080 ' #  + SWAP_ICON $'\uF464' #  + RAM_ICON $'\uF0E4' #  + SERVER_ICON $'\uF0AE' #  + VCS_UNTRACKED_ICON $'\uF059' #  + VCS_UNSTAGED_ICON $'\uF06A' #  + VCS_STAGED_ICON $'\uF055' #  + VCS_STASH_ICON $'\uF01C ' #  + VCS_INCOMING_CHANGES_ICON $'\uF01A ' #  + VCS_OUTGOING_CHANGES_ICON $'\uF01B ' #  + VCS_TAG_ICON $'\uF02B ' #  + VCS_BOOKMARK_ICON $'\uF461 ' #  + VCS_COMMIT_ICON $'\uE729 ' #  + VCS_BRANCH_ICON $'\uF126 ' #  + VCS_REMOTE_BRANCH_ICON $'\uE728 ' #  + VCS_GIT_ICON $'\uF1D3 ' #  + VCS_GIT_GITHUB_ICON $'\uF113 ' #  + VCS_GIT_BITBUCKET_ICON $'\uE703 ' #  + VCS_GIT_GITLAB_ICON $'\uF296 ' #  + VCS_HG_ICON $'\uF0C3 ' #  + VCS_SVN_ICON $'\uE72D ' #  + RUST_ICON $'\uE7A8 ' #  + PYTHON_ICON $'\UE73C ' #  + SWIFT_ICON $'\uE755' #  + GO_ICON $'\uE626' #  + PUBLIC_IP_ICON $'\UF0AC' #  + LOCK_ICON $'\UF023' #  + EXECUTION_TIME_ICON $'\uF252' #  + SSH_ICON $'\uF489' #  + VPN_ICON '(vpn)' + KUBERNETES_ICON $'\U2388' # ⎈ + DROPBOX_ICON $'\UF16B' #  + DATE_ICON $'\uF073 ' #  + TIME_ICON $'\uF017 ' #  + JAVA_ICON $'\U2615' # ☕︎ + LARAVEL_ICON $'\ue73f ' #  + ) + ;; + *) + # Powerline-Patched Font required! + # See https://github.com/Lokaltog/powerline-fonts + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" + icons=( + LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  + RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  + LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace + LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #  + RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  + CARRIAGE_RETURN_ICON $'\u21B5' # ↵ + ROOT_ICON $'\u26A1' # ⚡ + SUDO_ICON $'\uE0A2' #  + RUBY_ICON '' + AWS_ICON 'AWS:' + AWS_EB_ICON $'\U1F331 ' # 🌱 + BACKGROUND_JOBS_ICON $'\u2699' # ⚙ + TEST_ICON '' + TODO_ICON $'\u2611' # ☑ + BATTERY_ICON $'\U1F50B' # 🔋 + DISK_ICON $'hdd ' + OK_ICON $'\u2714' # ✔ + FAIL_ICON $'\u2718' # ✘ + SYMFONY_ICON 'SF' + NODE_ICON $'\u2B22' # ⬢ + MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ + MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─ + MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ + APPLE_ICON 'OSX' + WINDOWS_ICON 'WIN' + FREEBSD_ICON 'BSD' + ANDROID_ICON 'And' + LINUX_ICON 'Lx' + LINUX_ARCH_ICON 'Arc' + LINUX_DEBIAN_ICON 'Deb' + LINUX_UBUNTU_ICON 'Ubu' + LINUX_CENTOS_ICON 'Cen' + LINUX_COREOS_ICON 'Cor' + LINUX_ELEMENTARY_ICON 'Elm' + LINUX_MINT_ICON 'LMi' + LINUX_FEDORA_ICON 'Fed' + LINUX_GENTOO_ICON 'Gen' + LINUX_MAGEIA_ICON 'Mag' + LINUX_NIXOS_ICON 'Nix' + LINUX_MANJARO_ICON 'Man' + LINUX_DEVUAN_ICON 'Dev' + LINUX_ALPINE_ICON 'Alp' + LINUX_AOSC_ICON 'Aos' + LINUX_OPENSUSE_ICON 'OSu' + LINUX_SABAYON_ICON 'Sab' + LINUX_SLACKWARE_ICON 'Sla' + SUNOS_ICON 'Sun' + HOME_ICON '' + HOME_SUB_ICON '' + FOLDER_ICON '' + ETC_ICON $'\u2699' # ⚙ + NETWORK_ICON 'IP' + LOAD_ICON 'L' + SWAP_ICON 'SWP' + RAM_ICON 'RAM' + SERVER_ICON '' + VCS_UNTRACKED_ICON '?' + VCS_UNSTAGED_ICON $'\u25CF' # ● + VCS_STAGED_ICON $'\u271A' # ✚ + VCS_STASH_ICON $'\u235F' # ⍟ + VCS_INCOMING_CHANGES_ICON $'\u2193' # ↓ + VCS_OUTGOING_CHANGES_ICON $'\u2191' # ↑ + VCS_TAG_ICON '' + VCS_BOOKMARK_ICON $'\u263F' # ☿ + VCS_COMMIT_ICON '' + VCS_BRANCH_ICON $'\uE0A0 ' #  + VCS_REMOTE_BRANCH_ICON $'\u2192' # → + VCS_GIT_ICON '' + VCS_GIT_GITHUB_ICON '' + VCS_GIT_BITBUCKET_ICON '' + VCS_GIT_GITLAB_ICON '' + VCS_HG_ICON '' + VCS_SVN_ICON '' + RUST_ICON 'Rust' + PYTHON_ICON '' + SWIFT_ICON 'Swift' + GO_ICON 'Go' + PUBLIC_IP_ICON '' + LOCK_ICON $'\UE0A2' + EXECUTION_TIME_ICON 'Dur' + SSH_ICON '(ssh)' + VPN_ICON '(vpn)' + KUBERNETES_ICON $'\U2388' # ⎈ + DROPBOX_ICON 'Dropbox' + DATE_ICON '' + TIME_ICON '' + JAVA_ICON $'\U2615' # ☕︎ + LARAVEL_ICON '' + ) + ;; +esac + +# Override the above icon settings with any user-defined variables. +case $POWERLEVEL9K_MODE in + 'flat') + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" + icons[LEFT_SEGMENT_SEPARATOR]='' + icons[RIGHT_SEGMENT_SEPARATOR]='' + icons[LEFT_SUBSEGMENT_SEPARATOR]='|' + icons[RIGHT_SUBSEGMENT_SEPARATOR]='|' + ;; + 'compatible') + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" + icons[LEFT_SEGMENT_SEPARATOR]=$'\u2B80' # ⮀ + icons[RIGHT_SEGMENT_SEPARATOR]=$'\u2B82' # ⮂ + icons[VCS_BRANCH_ICON]='@' + ;; +esac + +if [[ "$POWERLEVEL9K_HIDE_BRANCH_ICON" == true ]]; then + icons[VCS_BRANCH_ICON]='' +fi + +# Safety function for printing icons +# Prints the named icon, or if that icon is undefined, the string name. +function print_icon() { + local icon_name=$1 + local ICON_USER_VARIABLE=POWERLEVEL9K_${icon_name} + if defined "$ICON_USER_VARIABLE"; then + echo -n "${(P)ICON_USER_VARIABLE}" + else + echo -n "${icons[$icon_name]}" + fi +} + +# Get a list of configured icons +# * $1 string - If "original", then the original icons are printed, +# otherwise "print_icon" is used, which takes the users +# overrides into account. +get_icon_names() { + # Iterate over a ordered list of keys of the icons array + for key in ${(@kon)icons}; do + echo -n "POWERLEVEL9K_$key: " + if [[ "${1}" == "original" ]]; then + # print the original icons as they are defined in the array above + echo "${icons[$key]}" + else + # print the icons as they are configured by the user + echo "$(print_icon "$key")" + fi + done +} diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/functions/utilities.zsh b/config/zsh/oh-my-zsh-custom/powerlevel9k/functions/utilities.zsh new file mode 100755 index 0000000..127007f --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/functions/utilities.zsh @@ -0,0 +1,373 @@ +# vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 +################################################################ +# Utility functions +# This file holds some utility-functions for +# the powerlevel9k-ZSH-theme +# https://github.com/bhilburn/powerlevel9k +################################################################ + +# Exits with 0 if a variable has been previously defined (even if empty) +# Takes the name of a variable that should be checked. +function defined() { + [[ ! -z "${(tP)1}" ]] +} + +# Given the name of a variable and a default value, sets the variable +# value to the default only if it has not been defined. +# +# Typeset cannot set the value for an array, so this will only work +# for scalar values. +function set_default() { + local varname="$1" + local default_value="$2" + + defined "$varname" || typeset -g "$varname"="$default_value" +} + +# Converts large memory values into a human-readable unit (e.g., bytes --> GB) +# Takes two arguments: +# * $size - The number which should be prettified +# * $base - The base of the number (default Bytes) +printSizeHumanReadable() { + typeset -F 2 size + size="$1"+0.00001 + local extension + extension=('B' 'K' 'M' 'G' 'T' 'P' 'E' 'Z' 'Y') + local index=1 + + # if the base is not Bytes + if [[ -n $2 ]]; then + local idx + for idx in "${extension[@]}"; do + if [[ "$2" == "$idx" ]]; then + break + fi + index=$(( index + 1 )) + done + fi + + while (( (size / 1024) > 0.1 )); do + size=$(( size / 1024 )) + index=$(( index + 1 )) + done + + echo "$size${extension[$index]}" +} + +# Gets the first value out of a list of items that is not empty. +# The items are examined by a callback-function. +# Takes two arguments: +# * $list - A list of items +# * $callback - A callback function to examine if the item is +# worthy. The callback function has access to +# the inner variable $item. +function getRelevantItem() { + local -a list + local callback + # Explicitly split the elements by whitespace. + list=(${=1}) + callback=$2 + + for item in $list; do + # The first non-empty item wins + try=$(eval "$callback") + if [[ -n "$try" ]]; then + echo "$try" + break; + fi + done +} + +# OS detection +case $(uname) in + Darwin) + OS='OSX' + OS_ICON=$(print_icon 'APPLE_ICON') + ;; + CYGWIN_NT-* | MSYS_NT-*) + OS='Windows' + OS_ICON=$(print_icon 'WINDOWS_ICON') + ;; + FreeBSD) + OS='BSD' + OS_ICON=$(print_icon 'FREEBSD_ICON') + ;; + OpenBSD) + OS='BSD' + OS_ICON=$(print_icon 'FREEBSD_ICON') + ;; + DragonFly) + OS='BSD' + OS_ICON=$(print_icon 'FREEBSD_ICON') + ;; + Linux) + OS='Linux' + os_release_id="$(grep -E '^ID=([a-zA-Z]*)' /etc/os-release | cut -d '=' -f 2)" + case "$os_release_id" in + *arch*) + OS_ICON=$(print_icon 'LINUX_ARCH_ICON') + ;; + *debian*) + OS_ICON=$(print_icon 'LINUX_DEBIAN_ICON') + ;; + *ubuntu*) + OS_ICON=$(print_icon 'LINUX_UBUNTU_ICON') + ;; + *elementary*) + OS_ICON=$(print_icon 'LINUX_ELEMENTARY_ICON') + ;; + *fedora*) + OS_ICON=$(print_icon 'LINUX_FEDORA_ICON') + ;; + *coreos*) + OS_ICON=$(print_icon 'LINUX_COREOS_ICON') + ;; + *gentoo*) + OS_ICON=$(print_icon 'LINUX_GENTOO_ICON') + ;; + *mageia*) + OS_ICON=$(print_icon 'LINUX_MAGEIA_ICON') + ;; + *centos*) + OS_ICON=$(print_icon 'LINUX_CENTOS_ICON') + ;; + *opensuse*|*tumbleweed*) + OS_ICON=$(print_icon 'LINUX_OPENSUSE_ICON') + ;; + *sabayon*) + OS_ICON=$(print_icon 'LINUX_SABAYON_ICON') + ;; + *slackware*) + OS_ICON=$(print_icon 'LINUX_SLACKWARE_ICON') + ;; + *linuxmint*) + OS_ICON=$(print_icon 'LINUX_MINT_ICON') + ;; + *alpine*) + OS_ICON=$(print_icon 'LINUX_ALPINE_ICON') + ;; + *aosc*) + OS_ICON=$(print_icon 'LINUX_AOSC_ICON') + ;; + *nixos*) + OS_ICON=$(print_icon 'LINUX_NIXOS_ICON') + ;; + *devuan*) + OS_ICON=$(print_icon 'LINUX_DEVUAN_ICON') + ;; + *manjaro*) + OS_ICON=$(print_icon 'LINUX_MANJARO_ICON') + ;; + *) + OS='Linux' + OS_ICON=$(print_icon 'LINUX_ICON') + ;; + esac + + # Check if we're running on Android + case $(uname -o 2>/dev/null) in + Android) + OS='Android' + OS_ICON=$(print_icon 'ANDROID_ICON') + ;; + esac + ;; + SunOS) + OS='Solaris' + OS_ICON=$(print_icon 'SUNOS_ICON') + ;; + *) + OS='' + OS_ICON='' + ;; +esac + +# Determine the correct sed parameter. +# +# `sed` is unfortunately not consistent across OSes when it comes to flags. +SED_EXTENDED_REGEX_PARAMETER="-r" +if [[ "$OS" == 'OSX' ]]; then + local IS_BSD_SED="$(sed --version &>> /dev/null || echo "BSD sed")" + if [[ -n "$IS_BSD_SED" ]]; then + SED_EXTENDED_REGEX_PARAMETER="-E" + fi +fi + +# Determine if the passed segment is used in the prompt +# +# Pass the name of the segment to this function to test for its presence in +# either the LEFT or RIGHT prompt arrays. +# * $1: The segment to be tested. +segment_in_use() { + local key=$1 + if [[ -n "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[(r)$key]}" ]] || [[ -n "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[(r)$key]}" ]]; then + return 0 + else + return 1 + fi +} + +# Print a deprecation warning if an old segment is in use. +# Takes the name of an associative array that contains the +# deprecated segments as keys, the values contain the new +# segment names. +print_deprecation_warning() { + typeset -AH raw_deprecated_segments + raw_deprecated_segments=(${(kvP@)1}) + + for key in ${(@k)raw_deprecated_segments}; do + if segment_in_use $key; then + # segment is deprecated + print -P "%F{yellow}Warning!%f The '$key' segment is deprecated. Use '%F{blue}${raw_deprecated_segments[$key]}%f' instead. For more informations, have a look at the CHANGELOG.md." + fi + done +} + +# A helper function to determine if a segment should be +# joined or promoted to a full one. +# Takes three arguments: +# * $1: The array index of the current segment +# * $2: The array index of the last printed segment +# * $3: The array of segments of the left or right prompt +function segmentShouldBeJoined() { + local current_index=$1 + local last_segment_index=$2 + # Explicitly split the elements by whitespace. + local -a elements + elements=(${=3}) + + local current_segment=${elements[$current_index]} + local joined=false + if [[ ${current_segment[-7,-1]} == '_joined' ]]; then + joined=true + # promote segment to a full one, if the predecessing full segment + # was conditional. So this can only be the case for segments that + # are not our direct predecessor. + if (( $(($current_index - $last_segment_index)) > 1)); then + # Now we have to examine every previous segment, until we reach + # the last printed one (found by its index). This is relevant if + # all previous segments are joined. Then we want to join our + # segment as well. + local examined_index=$((current_index - 1)) + while (( $examined_index > $last_segment_index )); do + local previous_segment=${elements[$examined_index]} + # If one of the examined segments is not joined, then we know + # that the current segment should not be joined, as the target + # segment is the wrong one. + if [[ ${previous_segment[-7,-1]} != '_joined' ]]; then + joined=false + break + fi + examined_index=$((examined_index - 1)) + done + fi + fi + + # Return 1 means error; return 0 means no error. So we have + # to invert $joined + if [[ "$joined" == "true" ]]; then + return 0 + else + return 1 + fi +} + +################################################################ +# Given a directory path, truncate it according to the settings. +# Parameters: +# * $1 Path: string - the directory path to be truncated +# * $2 Length: integer - length to truncate to +# * $3 Delimiter: string - the delimiter to use +# * $4 From: string - "right" | "middle". If omited, assumes right. +function truncatePath() { + # if the current path is not 1 character long (e.g. "/" or "~") + if (( ${#1} > 1 )); then + # convert $2 from string to integer + 2=$(( $2 )) + # set $3 to "" if not defined + [[ -z $3 ]] && 3="" || 3=$(echo -n $3) + # set $4 to "right" if not defined + [[ -z $4 ]] && 4="right" + # create a variable for the truncated path. + local trunc_path + # if the path is in the home folder, add "~/" to the start otherwise "/" + [[ $1 == "~"* ]] && trunc_path='~/' || trunc_path='/' + # split the path into an array using "/" as the delimiter + local paths=$1 + paths=(${(s:/:)${paths//"~\/"/}}) + # declare locals for the directory being tested and its length + local test_dir test_dir_length + # do the needed truncation + case $4 in + right) + # include the delimiter length in the threshhold + local threshhold=$(( $2 + ${#3} )) + # loop through the paths + for (( i=1; i<${#paths}; i++ )); do + # get the current directory value + test_dir=$paths[$i] + test_dir_length=${#test_dir} + # only truncate if the resulting truncation will be shorter than + # the truncation + delimiter length and at least 3 characters + if (( $test_dir_length > $threshhold )) && (( $test_dir_length > 3 )); then + # use the first $2 characters and the delimiter + trunc_path+="${test_dir:0:$2}$3/" + else + # use the full path + trunc_path+="${test_dir}/" + fi + done + ;; + middle) + # we need double the length for start and end truncation + delimiter length + local threshhold=$(( $2 * 2 )) + # create a variable for the start of the end truncation + local last_pos + # loop through the paths + for (( i=1; i<${#paths}; i++ )); do + # get the current directory value + test_dir=$paths[$i] + test_dir_length=${#test_dir} + # only truncate if the resulting truncation will be shorter than + # the truncation + delimiter length + if (( $test_dir_length > $threshhold )); then + # use the first $2 characters, the delimiter and the last $2 characters + last_pos=$(( $test_dir_length - $2 )) + trunc_path+="${test_dir:0:$2}$3${test_dir:$last_pos:$test_dir_length}/" + else + # use the full path + trunc_path+="${test_dir}/" + fi + done + ;; + esac + # return the truncated path + the current directory + echo $trunc_path${1:t} + else # current path is 1 character long (e.g. "/" or "~") + echo $1 + fi +} + +# Given a directory path, truncate it according to the settings for +# `truncate_from_right` +function truncatePathFromRight() { + local delim_len=${#POWERLEVEL9K_SHORTEN_DELIMITER:-1} + echo $1 | sed $SED_EXTENDED_REGEX_PARAMETER \ + "s@(([^/]{$((POWERLEVEL9K_SHORTEN_DIR_LENGTH))})([^/]{$delim_len}))[^/]+/@\2$POWERLEVEL9K_SHORTEN_DELIMITER/@g" +} + +# Search recursively in parent folders for given file. +function upsearch () { + if [[ "$PWD" == "$HOME" || "$PWD" == "/" ]]; then + echo "$PWD" + elif test -e "$1"; then + pushd .. > /dev/null + upsearch "$1" + popd > /dev/null + echo "$PWD" + else + pushd .. > /dev/null + upsearch "$1" + popd > /dev/null + fi +} diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/functions/vcs.zsh b/config/zsh/oh-my-zsh-custom/powerlevel9k/functions/vcs.zsh new file mode 100755 index 0000000..6c9bd05 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/functions/vcs.zsh @@ -0,0 +1,177 @@ +# vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 +################################################################ +# vcs +# This file holds supplemental VCS functions +# for the powerlevel9k-ZSH-theme +# https://github.com/bhilburn/powerlevel9k +################################################################ + +set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY false +function +vi-git-untracked() { + [[ -z "${vcs_comm[gitdir]}" || "${vcs_comm[gitdir]}" == "." ]] && return + # If we are in a .git folder, do not check for untracked files. + [[ "${PWD:A}" =~ "\.git/" ]] && return + + # If we are in a repos root folder, vcs_comm[gitdir] yields ".git". + # Inside the .git dir itself (and not a subdir of it) the variable + # yields ".". In any other case (either a subdirectory of .git or + # the repo itself), the value of vcs_comm[gitdir] is the absolute + # path to the .git directory. + # Therefore we can step up a directory, if we are inside the .git + # folder. And in any other case, use the parent directory of the + # gitdir. + local repoDir="." + # Getting the parent dir of the current dir "." is still ".", so + # is is safe to do this always. + [[ "${vcs_comm[gitdir]}" != ".git" ]] && repoDir="${vcs_comm[gitdir]:A:h}" + [[ "${vcs_comm[gitdir]}" == "." ]] && repoDir="${PWD:A:h}" + + if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard')" != "" ]]; then + hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" + VCS_WORKDIR_HALF_DIRTY=true + elif [[ "$(command git ls-files --others --exclude-standard "${repoDir}")" != "" ]]; then + hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" + VCS_WORKDIR_HALF_DIRTY=true + else + VCS_WORKDIR_HALF_DIRTY=false + fi +} + +function +vi-git-aheadbehind() { + local ahead behind + local -a gitstatus + + # for git prior to 1.7 + # ahead=$(command git rev-list origin/${hook_com[branch]}..HEAD | wc -l) + ahead=$(command git rev-list --count "${hook_com[branch]}"@{upstream}..HEAD 2>/dev/null) + (( ahead )) && gitstatus+=( " $(print_icon 'VCS_OUTGOING_CHANGES_ICON')${ahead// /}" ) + + # for git prior to 1.7 + # behind=$(command git rev-list HEAD..origin/${hook_com[branch]} | wc -l) + behind=$(command git rev-list --count HEAD.."${hook_com[branch]}"@{upstream} 2>/dev/null) + (( behind )) && gitstatus+=( " $(print_icon 'VCS_INCOMING_CHANGES_ICON')${behind// /}" ) + + hook_com[misc]+=${(j::)gitstatus} +} + +function +vi-git-remotebranch() { + local remote + local branch_name="${hook_com[branch]}" + + # Are we on a remote-tracking branch? + remote=${$(command git rev-parse --verify HEAD@{upstream} --symbolic-full-name 2>/dev/null)/refs\/(remotes|heads)\/} + + if [[ -n "$POWERLEVEL9K_VCS_SHORTEN_LENGTH" ]] && [[ -n "$POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH" ]]; then + set_default POWERLEVEL9K_VCS_SHORTEN_DELIMITER $'\U2026' + + if [ ${#hook_com[branch]} -gt ${POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH} ] && [ ${#hook_com[branch]} -gt ${POWERLEVEL9K_VCS_SHORTEN_LENGTH} ]; then + case "$POWERLEVEL9K_VCS_SHORTEN_STRATEGY" in + truncate_middle) + hook_com[branch]="${branch_name:0:$POWERLEVEL9K_VCS_SHORTEN_LENGTH}${POWERLEVEL9K_VCS_SHORTEN_DELIMITER}${branch_name: -$POWERLEVEL9K_VCS_SHORTEN_LENGTH}" + ;; + truncate_from_right) + hook_com[branch]="${branch_name:0:$POWERLEVEL9K_VCS_SHORTEN_LENGTH}${POWERLEVEL9K_VCS_SHORTEN_DELIMITER}" + ;; + esac + fi + fi + + hook_com[branch]="$(print_icon 'VCS_BRANCH_ICON')${hook_com[branch]}" + # Always show the remote + #if [[ -n ${remote} ]] ; then + # Only show the remote if it differs from the local + if [[ -n ${remote} ]] && [[ "${remote#*/}" != "${branch_name}" ]] ; then + hook_com[branch]+="$(print_icon 'VCS_REMOTE_BRANCH_ICON')${remote// /}" + fi +} + +set_default POWERLEVEL9K_VCS_HIDE_TAGS false +function +vi-git-tagname() { + if [[ "$POWERLEVEL9K_VCS_HIDE_TAGS" == "false" ]]; then + # If we are on a tag, append the tagname to the current branch string. + local tag + tag=$(command git describe --tags --exact-match HEAD 2>/dev/null) + + if [[ -n "${tag}" ]] ; then + # There is a tag that points to our current commit. Need to determine if we + # are also on a branch, or are in a DETACHED_HEAD state. + if [[ -z $(command git symbolic-ref HEAD 2>/dev/null) ]]; then + # DETACHED_HEAD state. We want to append the tag name to the commit hash + # and print it. Unfortunately, `vcs_info` blows away the hash when a tag + # exists, so we have to manually retrieve it and clobber the branch + # string. + local revision + revision=$(command git rev-list -n 1 --abbrev-commit --abbrev=${POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH} HEAD) + hook_com[branch]="$(print_icon 'VCS_BRANCH_ICON')${revision} $(print_icon 'VCS_TAG_ICON')${tag}" + else + # We are on both a tag and a branch; print both by appending the tag name. + hook_com[branch]+=" $(print_icon 'VCS_TAG_ICON')${tag}" + fi + fi + fi +} + +# Show count of stashed changes +# Port from https://github.com/whiteinge/dotfiles/blob/5dfd08d30f7f2749cfc60bc55564c6ea239624d9/.zsh_shouse_prompt#L268 +function +vi-git-stash() { + if [[ -s "${vcs_comm[gitdir]}/logs/refs/stash" ]] ; then + local -a stashes=( "${(@f)"$(<${vcs_comm[gitdir]}/logs/refs/stash)"}" ) + hook_com[misc]+=" $(print_icon 'VCS_STASH_ICON')${#stashes}" + fi +} + +function +vi-hg-bookmarks() { + if [[ -n "${hgbmarks[@]}" ]]; then + hook_com[hg-bookmark-string]=" $(print_icon 'VCS_BOOKMARK_ICON')${hgbmarks[@]}" + + # To signal that we want to use the sting we just generated, set the special + # variable `ret' to something other than the default zero: + ret=1 + return 0 + fi +} + +function +vi-vcs-detect-changes() { + if [[ "${hook_com[vcs]}" == "git" ]]; then + + local remote=$(command git ls-remote --get-url 2> /dev/null) + if [[ "$remote" =~ "github" ]] then + vcs_visual_identifier='VCS_GIT_GITHUB_ICON' + elif [[ "$remote" =~ "bitbucket" ]] then + vcs_visual_identifier='VCS_GIT_BITBUCKET_ICON' + elif [[ "$remote" =~ "stash" ]] then + vcs_visual_identifier='VCS_GIT_BITBUCKET_ICON' + elif [[ "$remote" =~ "gitlab" ]] then + vcs_visual_identifier='VCS_GIT_GITLAB_ICON' + else + vcs_visual_identifier='VCS_GIT_ICON' + fi + + elif [[ "${hook_com[vcs]}" == "hg" ]]; then + vcs_visual_identifier='VCS_HG_ICON' + elif [[ "${hook_com[vcs]}" == "svn" ]]; then + vcs_visual_identifier='VCS_SVN_ICON' + fi + + if [[ -n "${hook_com[staged]}" ]] || [[ -n "${hook_com[unstaged]}" ]]; then + VCS_WORKDIR_DIRTY=true + else + VCS_WORKDIR_DIRTY=false + fi +} + +function +vi-svn-detect-changes() { + local svn_status="$(svn status)" + if [[ -n "$(echo "$svn_status" | \grep \^\?)" ]]; then + hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" + VCS_WORKDIR_HALF_DIRTY=true + fi + if [[ -n "$(echo "$svn_status" | \grep \^\M)" ]]; then + hook_com[unstaged]+=" $(print_icon 'VCS_UNSTAGED_ICON')" + VCS_WORKDIR_DIRTY=true + fi + if [[ -n "$(echo "$svn_status" | \grep \^\A)" ]]; then + hook_com[staged]+=" $(print_icon 'VCS_STAGED_ICON')" + VCS_WORKDIR_DIRTY=true + fi +} diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/powerlevel9k.zsh-theme b/config/zsh/oh-my-zsh-custom/powerlevel9k/powerlevel9k.zsh-theme new file mode 100755 index 0000000..3c3303f --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/powerlevel9k.zsh-theme @@ -0,0 +1,1955 @@ +# vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 +################################################################ +# powerlevel9k Theme +# https://github.com/bhilburn/powerlevel9k +# +# This theme was inspired by agnoster's Theme: +# https://gist.github.com/3712874 +################################################################ + +################################################################ +# For basic documentation, please refer to the README.md in the top-level +# directory. For more detailed documentation, refer to the project wiki, hosted +# on Github: https://github.com/bhilburn/powerlevel9k/wiki +# +# There are a lot of easy ways you can customize your prompt segments and +# theming with simple variables defined in your `~/.zshrc`. +################################################################ + +## Turn on for Debugging +#PS4='%s%f%b%k%F{blue}%{λ%}%L %F{240}%N:%i%(?.. %F{red}%?) %1(_.%F{yellow}%-1_ .)%s%f%b%k ' +#zstyle ':vcs_info:*+*:*' debug true +#set -o xtrace + +# Try to set the installation path +if [[ -n "$POWERLEVEL9K_INSTALLATION_DIR" ]]; then + p9k_directory=${POWERLEVEL9K_INSTALLATION_DIR:A} +else + if [[ "${(%):-%N}" == '(eval)' ]]; then + if [[ "$0" == '-antigen-load' ]] && [[ -r "${PWD}/powerlevel9k.zsh-theme" ]]; then + # Antigen uses eval to load things so it can change the plugin (!!) + # https://github.com/zsh-users/antigen/issues/581 + p9k_directory=$PWD + else + print -P "%F{red}You must set POWERLEVEL9K_INSTALLATION_DIR work from within an (eval).%f" + return 1 + fi + else + # Get the path to file this code is executing in; then + # get the absolute path and strip the filename. + # See https://stackoverflow.com/a/28336473/108857 + p9k_directory=${${(%):-%x}:A:h} + fi +fi + +################################################################ +# Source icon functions +################################################################ + +source "${p9k_directory}/functions/icons.zsh" + +################################################################ +# Source utility functions +################################################################ + +source "${p9k_directory}/functions/utilities.zsh" + +################################################################ +# Source color functions +################################################################ + +source "${p9k_directory}/functions/colors.zsh" + +################################################################ +# Source VCS_INFO hooks / helper functions +################################################################ + +source "${p9k_directory}/functions/vcs.zsh" + +# cleanup temporary variables. +unset p9k_directory + +################################################################ +# Color Scheme +################################################################ + +if [[ "$POWERLEVEL9K_COLOR_SCHEME" == "light" ]]; then + DEFAULT_COLOR=white + DEFAULT_COLOR_INVERTED=black +else + DEFAULT_COLOR=black + DEFAULT_COLOR_INVERTED=white +fi + +################################################################ +# Prompt Segment Constructors +# +# Methodology behind user-defined variables overwriting colors: +# The first parameter to the segment constructors is the calling function's +# name. From this function name, we strip the "prompt_"-prefix and +# uppercase it. This is then prefixed with "POWERLEVEL9K_" and suffixed +# with either "_BACKGROUND" or "_FOREGROUND", thus giving us the variable +# name. So each new segment is user-overwritten by a variable following +# this naming convention. +################################################################ + +# The `CURRENT_BG` variable is used to remember what the last BG color used was +# when building the left-hand prompt. Because the RPROMPT is created from +# right-left but reads the opposite, this isn't necessary for the other side. +CURRENT_BG='NONE' + +# Begin a left prompt segment +# Takes four arguments: +# * $1: Name of the function that was originally invoked (mandatory). +# Necessary, to make the dynamic color-overwrite mechanism work. +# * $2: The array index of the current segment +# * $3: Background color +# * $4: Foreground color +# * $5: The segment content +# * $6: An identifying icon (must be a key of the icons array) +# The latter three can be omitted, +set_default last_left_element_index 1 +set_default POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS " " +left_prompt_segment() { + local segment_name="${1}" + local current_index=$2 + # Check if the segment should be joined with the previous one + local joined + segmentShouldBeJoined $current_index $last_left_element_index "$POWERLEVEL9K_LEFT_PROMPT_ELEMENTS" && joined=true || joined=false + + # Colors + local backgroundColor="${3}" + local foregroundColor="${4}" + + # Overwrite given background-color by user defined variable for this segment. + local BACKGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)${segment_name}#prompt_}_BACKGROUND + local BG_COLOR_MODIFIER=${(P)BACKGROUND_USER_VARIABLE} + [[ -n $BG_COLOR_MODIFIER ]] && backgroundColor="$BG_COLOR_MODIFIER" + + # Overwrite given foreground-color by user defined variable for this segment. + local FOREGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)${segment_name}#prompt_}_FOREGROUND + local FG_COLOR_MODIFIER=${(P)FOREGROUND_USER_VARIABLE} + [[ -n $FG_COLOR_MODIFIER ]] && foregroundColor="$FG_COLOR_MODIFIER" + + # Get color codes here to save some calls later on + backgroundColor="$(getColorCode ${backgroundColor})" + foregroundColor="$(getColorCode ${foregroundColor})" + + local background foreground + [[ -n "${backgroundColor}" ]] && background="$(backgroundColor ${backgroundColor})" || background="%k" + [[ -n "${foregroundColor}" ]] && foreground="$(foregroundColor ${foregroundColor})" || foreground="%f" + + if [[ $CURRENT_BG != 'NONE' ]] && ! isSameColor "${backgroundColor}" "$CURRENT_BG"; then + echo -n "${background}%F{$CURRENT_BG}" + if [[ $joined == false ]]; then + # Middle segment + echo -n "$(print_icon 'LEFT_SEGMENT_SEPARATOR')$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + fi + elif isSameColor "$CURRENT_BG" "${backgroundColor}"; then + # Middle segment with same color as previous segment + # We take the current foreground color as color for our + # subsegment (or the default color). This should have + # enough contrast. + local complement + [[ -n "${foregroundColor}" ]] && complement="${foreground}" || complement="$(foregroundColor $DEFAULT_COLOR)" + echo -n "${background}${complement}" + if [[ $joined == false ]]; then + echo -n "$(print_icon 'LEFT_SUBSEGMENT_SEPARATOR')$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + fi + else + # First segment + echo -n "${background}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + fi + + local visual_identifier + if [[ -n $6 ]]; then + visual_identifier="$(print_icon $6)" + if [[ -n "$visual_identifier" ]]; then + # Add an whitespace if we print more than just the visual identifier. + # To avoid cutting off the visual identifier in some terminal emulators (e.g., Konsole, st), + # we need to color both the visual identifier and the whitespace. + [[ -n "$5" ]] && visual_identifier="$visual_identifier " + # Allow users to overwrite the color for the visual identifier only. + local visual_identifier_color_variable=POWERLEVEL9K_${(U)${segment_name}#prompt_}_VISUAL_IDENTIFIER_COLOR + set_default $visual_identifier_color_variable "${foregroundColor}" + visual_identifier="$(foregroundColor ${(P)visual_identifier_color_variable})${visual_identifier}%f" + fi + fi + + # Print the visual identifier + echo -n "${visual_identifier}" + # Print the content of the segment, if there is any + [[ -n "$5" ]] && echo -n "${foreground}${5}" + echo -n "${POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS}" + + CURRENT_BG="${backgroundColor}" + last_left_element_index=$current_index +} + +# End the left prompt, closes the final segment. +left_prompt_end() { + if [[ -n $CURRENT_BG ]]; then + echo -n "%k$(foregroundColor ${CURRENT_BG})$(print_icon 'LEFT_SEGMENT_SEPARATOR')" + else + echo -n "%k" + fi + echo -n "%f$(print_icon 'LEFT_SEGMENT_END_SEPARATOR')" + CURRENT_BG='' +} + +CURRENT_RIGHT_BG='NONE' + +# Begin a right prompt segment +# Takes four arguments: +# * $1: Name of the function that was originally invoked (mandatory). +# Necessary, to make the dynamic color-overwrite mechanism work. +# * $2: The array index of the current segment +# * $3: Background color +# * $4: Foreground color +# * $5: The segment content +# * $6: An identifying icon (must be a key of the icons array) +# No ending for the right prompt segment is needed (unlike the left prompt, above). +set_default last_right_element_index 1 +set_default POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS " " +right_prompt_segment() { + local segment_name="${1}" + local current_index=$2 + + # Check if the segment should be joined with the previous one + local joined + segmentShouldBeJoined $current_index $last_right_element_index "$POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS" && joined=true || joined=false + + # Colors + local backgroundColor="${3}" + local foregroundColor="${4}" + + # Overwrite given background-color by user defined variable for this segment. + local BACKGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)${segment_name}#prompt_}_BACKGROUND + local BG_COLOR_MODIFIER=${(P)BACKGROUND_USER_VARIABLE} + [[ -n $BG_COLOR_MODIFIER ]] && backgroundColor="$BG_COLOR_MODIFIER" + + # Overwrite given foreground-color by user defined variable for this segment. + local FOREGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)${segment_name}#prompt_}_FOREGROUND + local FG_COLOR_MODIFIER=${(P)FOREGROUND_USER_VARIABLE} + [[ -n $FG_COLOR_MODIFIER ]] && foregroundColor="$FG_COLOR_MODIFIER" + + # Get color codes here to save some calls later on + backgroundColor="$(getColorCode ${backgroundColor})" + foregroundColor="$(getColorCode ${foregroundColor})" + + local background foreground + [[ -n "${backgroundColor}" ]] && background="$(backgroundColor ${backgroundColor})" || background="%k" + [[ -n "${foregroundColor}" ]] && foreground="$(foregroundColor ${foregroundColor})" || foreground="%f" + + # If CURRENT_RIGHT_BG is "NONE", we are the first right segment. + + if [[ "$CURRENT_RIGHT_BG" != "NONE" ]]; then + # This is the closing whitespace for the previous segment + echo -n "${POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS}%f" + fi + + if [[ $joined == false ]] || [[ "$CURRENT_RIGHT_BG" == "NONE" ]]; then + if isSameColor "$CURRENT_RIGHT_BG" "${backgroundColor}"; then + # Middle segment with same color as previous segment + # We take the current foreground color as color for our + # subsegment (or the default color). This should have + # enough contrast. + local complement + [[ -n "${foregroundColor}" ]] && complement="${foreground}" || complement="$(foregroundColor $DEFAULT_COLOR)" + echo -n "$complement$(print_icon 'RIGHT_SUBSEGMENT_SEPARATOR')%f" + else + # Use the new Background Color as the foreground of the segment separator + echo -n "$(foregroundColor ${backgroundColor})$(print_icon 'RIGHT_SEGMENT_SEPARATOR')%f" + fi + fi + + local visual_identifier + if [[ -n "$6" ]]; then + visual_identifier="$(print_icon $6)" + if [[ -n "$visual_identifier" ]]; then + # Add an whitespace if we print more than just the visual identifier. + # To avoid cutting off the visual identifier in some terminal emulators (e.g., Konsole, st), + # we need to color both the visual identifier and the whitespace. + [[ -n "$5" ]] && visual_identifier=" $visual_identifier" + # Allow users to overwrite the color for the visual identifier only. + local visual_identifier_color_variable=POWERLEVEL9K_${(U)${segment_name}#prompt_}_VISUAL_IDENTIFIER_COLOR + set_default $visual_identifier_color_variable "${foregroundColor}" + visual_identifier="$(foregroundColor ${(P)visual_identifier_color_variable})${visual_identifier}%f" + fi + fi + + echo -n "${background}${foreground}" + + # Print whitespace only if segment is not joined or first right segment + [[ $joined == false ]] || [[ "$CURRENT_RIGHT_BG" == "NONE" ]] && echo -n "${POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS}" + + # Print segment content if there is any + [[ -n "$5" ]] && echo -n "${5}" + # Print the visual identifier + echo -n "${visual_identifier}" + + CURRENT_RIGHT_BG="${backgroundColor}" + last_right_element_index=$current_index +} + +################################################################ +# Prompt Segment Definitions +################################################################ + +################################################################ +# Anaconda Environment +prompt_anaconda() { + # Depending on the conda version, either might be set. This + # variant works even if both are set. + local _path=$CONDA_ENV_PATH$CONDA_PREFIX + if ! [ -z "$_path" ]; then + # config - can be overwritten in users' zshrc file. + set_default POWERLEVEL9K_ANACONDA_LEFT_DELIMITER "(" + set_default POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER ")" + "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$POWERLEVEL9K_ANACONDA_LEFT_DELIMITER$(basename $_path)$POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER" 'PYTHON_ICON' + fi +} + +################################################################ +# AWS Profile +prompt_aws() { + local aws_profile="${AWS_PROFILE:-$AWS_DEFAULT_PROFILE}" + + if [[ -n "$aws_profile" ]]; then + "$1_prompt_segment" "$0" "$2" red white "$aws_profile" 'AWS_ICON' + fi +} + +################################################################ +# Current Elastic Beanstalk environment +prompt_aws_eb_env() { + local eb_env=$(grep environment .elasticbeanstalk/config.yml 2> /dev/null | awk '{print $2}') + + if [[ -n "$eb_env" ]]; then + "$1_prompt_segment" "$0" "$2" black green "$eb_env" 'AWS_EB_ICON' + fi +} + +################################################################ +# Segment to indicate background jobs with an icon. +set_default POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE true +set_default POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE_ALWAYS false +prompt_background_jobs() { + local background_jobs_number=${$(jobs -l | wc -l)// /} + local wrong_lines=`jobs -l | awk '/pwd now/{ count++ } END {print count}'` + if [[ wrong_lines -gt 0 ]]; then + background_jobs_number=$(( $background_jobs_number - $wrong_lines )) + fi + if [[ background_jobs_number -gt 0 ]]; then + local background_jobs_number_print="" + if [[ "$POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE" == "true" ]] && ([[ "$background_jobs_number" -gt 1 ]] || [[ "$POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE_ALWAYS" == "true" ]]); then + background_jobs_number_print="$background_jobs_number" + fi + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "cyan" "$background_jobs_number_print" 'BACKGROUND_JOBS_ICON' + fi +} + +################################################################ +# A newline in your prompt, so you can segments on multiple lines. +prompt_newline() { + local lws newline + [[ "$1" == "right" ]] && return + newline=$'\n' + lws=$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS + if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then + newline="${newline}$(print_icon 'MULTILINE_NEWLINE_PROMPT_PREFIX')" + fi + POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS= + "$1_prompt_segment" \ + "$0" \ + "$2" \ + "NONE" "NONE" "${newline}" + POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS=$lws +} + +################################################################ +# Segment that indicates usage level of current partition. +set_default POWERLEVEL9K_DISK_USAGE_ONLY_WARNING false +set_default POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL 90 +set_default POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL 95 +prompt_disk_usage() { + local current_state="unknown" + typeset -AH hdd_usage_forecolors + hdd_usage_forecolors=( + 'normal' 'yellow' + 'warning' "$DEFAULT_COLOR" + 'critical' 'white' + ) + typeset -AH hdd_usage_backcolors + hdd_usage_backcolors=( + 'normal' $DEFAULT_COLOR + 'warning' 'yellow' + 'critical' 'red' + ) + + local disk_usage="${$(\df -P . | sed -n '2p' | awk '{ print $5 }')%%\%}" + + if [ "$disk_usage" -ge "$POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL" ]; then + current_state='warning' + if [ "$disk_usage" -ge "$POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL" ]; then + current_state='critical' + fi + else + if [[ "$POWERLEVEL9K_DISK_USAGE_ONLY_WARNING" == true ]]; then + current_state='' + return + fi + current_state='normal' + fi + + local message="${disk_usage}%%" + + # Draw the prompt_segment + if [[ -n $disk_usage ]]; then + "$1_prompt_segment" "${0}_${current_state}" "$2" "${hdd_usage_backcolors[$current_state]}" "${hdd_usage_forecolors[$current_state]}" "$message" 'DISK_ICON' + fi +} + +################################################################ +# Segment that displays the battery status in levels and colors +prompt_battery() { + # The battery can have four different states - default to 'unknown'. + local current_state='unknown' + typeset -AH battery_states + battery_states=( + 'low' 'red' + 'charging' 'yellow' + 'charged' 'green' + 'disconnected' "$DEFAULT_COLOR_INVERTED" + ) + local ROOT_PREFIX="${4}" + # Set default values if the user did not configure them + set_default POWERLEVEL9K_BATTERY_LOW_THRESHOLD 10 + + if [[ $OS =~ OSX && -f "${ROOT_PREFIX}"/usr/bin/pmset && -x "${ROOT_PREFIX}"/usr/bin/pmset ]]; then + # obtain battery information from system + local raw_data="$(${ROOT_PREFIX}/usr/bin/pmset -g batt | awk 'FNR==2{print}')" + # return if there is no battery on system + [[ -z $(echo $raw_data | grep "InternalBattery") ]] && return + + # Time remaining on battery operation (charging/discharging) + local tstring=$(echo $raw_data | awk -F ';' '{print $3}' | awk '{print $1}') + # If time has not been calculated by system yet + [[ $tstring =~ '(\(no|not)' ]] && tstring="..." + + # percent of battery charged + typeset -i 10 bat_percent + bat_percent=$(echo $raw_data | grep -o '[0-9]*%' | sed 's/%//') + + local remain="" + # Logic for string output + case $(echo $raw_data | awk -F ';' '{print $2}' | awk '{$1=$1};1') in + # for a short time after attaching power, status will be 'AC attached;' + 'charging'|'finishing charge'|'AC attached') + current_state="charging" + remain=" ($tstring)" + ;; + 'discharging') + [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && current_state="low" || current_state="disconnected" + remain=" ($tstring)" + ;; + *) + current_state="charged" + ;; + esac + fi + + if [[ "$OS" == 'Linux' ]] || [[ "$OS" == 'Android' ]]; then + local sysp="${ROOT_PREFIX}/sys/class/power_supply" + + # Reported BAT0 or BAT1 depending on kernel version + [[ -a $sysp/BAT0 ]] && local bat=$sysp/BAT0 + [[ -a $sysp/BAT1 ]] && local bat=$sysp/BAT1 + + # Android-related + # Tested on: Moto G falcon (CM 13.0) + [[ -a $sysp/battery ]] && local bat=$sysp/battery + + # Return if no battery found + [[ -z $bat ]] && return + local capacity=$(cat $bat/capacity) + local battery_status=$(cat $bat/status) + [[ $capacity -gt 100 ]] && local bat_percent=100 || local bat_percent=$capacity + [[ $battery_status =~ Charging || $battery_status =~ Full ]] && local connected=true + if [[ -z $connected ]]; then + [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && current_state="low" || current_state="disconnected" + else + [[ $bat_percent =~ 100 ]] && current_state="charged" + [[ $bat_percent -lt 100 ]] && current_state="charging" + fi + if [[ -f ${ROOT_PREFIX}/usr/bin/acpi ]]; then + local time_remaining=$(${ROOT_PREFIX}/usr/bin/acpi | awk '{ print $5 }') + if [[ $time_remaining =~ rate ]]; then + local tstring="..." + elif [[ $time_remaining =~ "[[:digit:]]+" ]]; then + local tstring=${(f)$(date -u -d "$(echo $time_remaining)" +%k:%M 2> /dev/null)} + fi + fi + [[ -n $tstring ]] && local remain=" ($tstring)" + fi + + local message + # Default behavior: Be verbose! + set_default POWERLEVEL9K_BATTERY_VERBOSE true + if [[ "$POWERLEVEL9K_BATTERY_VERBOSE" == true ]]; then + message="$bat_percent%%$remain" + else + message="$bat_percent%%" + fi + + # override default icon if we are using battery stages + if [[ -n "$POWERLEVEL9K_BATTERY_STAGES" ]]; then + local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_STAGES} - 1 ) )) + if [[ $segment > 1 ]]; then + local offset=$(( ($bat_percent / $segment) + 1 )) + # check if the stages are in an array or a string + [[ "${(t)POWERLEVEL9K_BATTERY_STAGES}" =~ "array" ]] && POWERLEVEL9K_BATTERY_ICON="$POWERLEVEL9K_BATTERY_STAGES[$offset]" || POWERLEVEL9K_BATTERY_ICON=${POWERLEVEL9K_BATTERY_STAGES:$offset:1} + fi + fi + # return if POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD is set and the battery percentage is greater or equal + if defined POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD && [[ "${bat_percent}" -ge $POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD ]]; then + return + fi + + # override the default color if we are using a color level array + if [[ -n "$POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND" ]] && [[ "${(t)POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND}" =~ "array" ]]; then + local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND} - 1 ) )) + local offset=$(( ($bat_percent / $segment) + 1 )) + "$1_prompt_segment" "$0_${current_state}" "$2" "${POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[$offset]}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" + else + # Draw the prompt_segment + "$1_prompt_segment" "$0_${current_state}" "$2" "${DEFAULT_COLOR}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" + fi +} + +################################################################ +# Public IP segment +# Parameters: +# * $1 Alignment: string - left|right +# * $2 Index: integer +# * $3 Joined: bool - If the segment should be joined +prompt_public_ip() { + # set default values for segment + set_default POWERLEVEL9K_PUBLIC_IP_TIMEOUT "300" + set_default POWERLEVEL9K_PUBLIC_IP_NONE "" + set_default POWERLEVEL9K_PUBLIC_IP_FILE "/tmp/p9k_public_ip" + set_default POWERLEVEL9K_PUBLIC_IP_HOST "http://ident.me" + defined POWERLEVEL9K_PUBLIC_IP_METHODS || POWERLEVEL9K_PUBLIC_IP_METHODS=(dig curl wget) + + # Do we need a fresh IP? + local refresh_ip=false + if [[ -f $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then + typeset -i timediff + # if saved IP is more than + if [[ "$OS" == "OSX" ]]; then + timediff=$(($(date +%s) - $(stat -f "%m" $POWERLEVEL9K_PUBLIC_IP_FILE))) + else + timediff=$(($(date +%s) - $(date -r $POWERLEVEL9K_PUBLIC_IP_FILE +%s))) + fi + [[ $timediff -gt $POWERLEVEL9K_PUBLIC_IP_TIMEOUT ]] && refresh_ip=true + # If tmp file is empty get a fresh IP + [[ -z $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) ]] && refresh_ip=true + [[ -n $POWERLEVEL9K_PUBLIC_IP_NONE ]] && [[ $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) =~ "$POWERLEVEL9K_PUBLIC_IP_NONE" ]] && refresh_ip=true + else + touch $POWERLEVEL9K_PUBLIC_IP_FILE && refresh_ip=true + fi + + # grab a fresh IP if needed + local fresh_ip + if [[ $refresh_ip =~ true && -w $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then + for method in "${POWERLEVEL9K_PUBLIC_IP_METHODS[@]}"; do + case $method in + 'dig') + fresh_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com 2> /dev/null)" + [[ "$fresh_ip" =~ ^\; ]] && unset fresh_ip + ;; + 'curl') + fresh_ip="$(curl --max-time 10 -w '\n' "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)" + ;; + 'wget') + fresh_ip="$(wget -T 10 -qO- "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)" + ;; + esac + # If we found a fresh IP, break loop. + if [[ -n "${fresh_ip}" ]]; then + break; + fi + done + + # write IP to tmp file or clear tmp file if an IP was not retrieved + # Redirection with `>!`. From the manpage: Same as >, except that the file + # is truncated to zero length if it exists, even if CLOBBER is unset. + # If the file already exists, and a simple `>` redirection and CLOBBER + # unset, ZSH will produce an error. + [[ -n "${fresh_ip}" ]] && echo $fresh_ip >! $POWERLEVEL9K_PUBLIC_IP_FILE || echo $POWERLEVEL9K_PUBLIC_IP_NONE >! $POWERLEVEL9K_PUBLIC_IP_FILE + fi + + # read public IP saved to tmp file + local public_ip="$(cat $POWERLEVEL9K_PUBLIC_IP_FILE)" + + # Draw the prompt segment + if [[ -n $public_ip ]]; then + icon='PUBLIC_IP_ICON' + # Check VPN is on if VPN interface is set + if [[ -n $POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ]]; then + for vpn_iface in $(/sbin/ifconfig | grep -e ^"$POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE" | cut -d":" -f1) + do + icon='VPN_ICON' + break + done + fi + $1_prompt_segment "$0" "$2" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "${public_ip}" "$icon" + fi +} + +################################################################ +# Context: user@hostname (who am I and where am I) +# Note that if $DEFAULT_USER is not set, this prompt segment will always print +set_default POWERLEVEL9K_ALWAYS_SHOW_CONTEXT false +set_default POWERLEVEL9K_ALWAYS_SHOW_USER false +set_default POWERLEVEL9K_CONTEXT_TEMPLATE "%n@%m" +prompt_context() { + local current_state="DEFAULT" + typeset -AH context_states + context_states=( + "ROOT" "yellow" + "SUDO" "yellow" + "DEFAULT" "yellow" + "REMOTE" "yellow" + "REMOTE_SUDO" "yellow" + ) + + local content="" + + if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$(whoami)" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then + content="${POWERLEVEL9K_CONTEXT_TEMPLATE}" + elif [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]]; then + content="$(whoami)" + else + return + fi + + if [[ $(print -P "%#") == '#' ]]; then + current_state="ROOT" + elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then + if [[ -n "$SUDO_COMMAND" ]]; then + current_state="REMOTE_SUDO" + else + current_state="REMOTE" + fi + elif [[ -n "$SUDO_COMMAND" ]]; then + current_state="SUDO" + fi + + "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}" +} + +################################################################ +# User: user (who am I) +# Note that if $DEFAULT_USER is not set, this prompt segment will always print +set_default POWERLEVEL9K_USER_TEMPLATE "%n" +prompt_user() { + local current_state="DEFAULT" + typeset -AH user_state + if [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]] || [[ "$(whoami)" != "$DEFAULT_USER" ]]; then + if [[ $(print -P "%#") == '#' ]]; then + user_state=( + "STATE" "ROOT" + "CONTENT" "${POWERLEVEL9K_USER_TEMPLATE}" + "BACKGROUND_COLOR" "${DEFAULT_COLOR}" + "FOREGROUND_COLOR" "yellow" + "VISUAL_IDENTIFIER" "ROOT_ICON" + ) + elif [[ -n "$SUDO_COMMAND" ]]; then + user_state=( + "STATE" "SUDO" + "CONTENT" "${POWERLEVEL9K_USER_TEMPLATE}" + "BACKGROUND_COLOR" "${DEFAULT_COLOR}" + "FOREGROUND_COLOR" "yellow" + "VISUAL_IDENTIFIER" "SUDO_ICON" + ) + else + user_state=( + "STATE" "DEFAULT" + "CONTENT" "$(whoami)" + "BACKGROUND_COLOR" "${DEFAULT_COLOR}" + "FOREGROUND_COLOR" "yellow" + "VISUAL_IDENTIFIER" "USER_ICON" + ) + fi + "$1_prompt_segment" "${0}_${user_state[STATE]}" "$2" "${user_state[BACKGROUND_COLOR]}" "${user_state[FOREGROUND_COLOR]}" "${user_state[CONTENT]}" "${user_state[VISUAL_IDENTIFIER]}" + fi +} + +################################################################ +# Host: machine (where am I) +set_default POWERLEVEL9K_HOST_TEMPLATE "%m" +prompt_host() { + local current_state="LOCAL" + typeset -AH host_state + if [[ -n "$SSH_CLIENT" ]] || [[ -n "$SSH_TTY" ]]; then + host_state=( + "STATE" "REMOTE" + "CONTENT" "${POWERLEVEL9K_HOST_TEMPLATE}" + "BACKGROUND_COLOR" "${DEFAULT_COLOR}" + "FOREGROUND_COLOR" "yellow" + "VISUAL_IDENTIFIER" "SSH_ICON" + ) + else + host_state=( + "STATE" "LOCAL" + "CONTENT" "${POWERLEVEL9K_HOST_TEMPLATE}" + "BACKGROUND_COLOR" "${DEFAULT_COLOR}" + "FOREGROUND_COLOR" "yellow" + "VISUAL_IDENTIFIER" "HOST_ICON" + ) + fi + "$1_prompt_segment" "$0_${host_state[STATE]}" "$2" "${host_state[BACKGROUND_COLOR]}" "${host_state[FOREGROUND_COLOR]}" "${host_state[CONTENT]}" "${host_state[VISUAL_IDENTIFIER]}" +} + +################################################################ +# The 'custom` prompt provides a way for users to invoke commands and display +# the output in a segment. +prompt_custom() { + local segment_name="${3:u}" + # Get content of custom segment + local command="POWERLEVEL9K_CUSTOM_${segment_name}" + local segment_content="$(eval ${(P)command})" + + if [[ -n $segment_content ]]; then + "$1_prompt_segment" "${0}_${3:u}" "$2" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "$segment_content" "CUSTOM_${segment_name}_ICON" + fi +} + +################################################################ +# Display the duration the command needed to run. +prompt_command_execution_time() { + set_default POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD 3 + set_default POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION 2 + + # Print time in human readable format + # For that use `strftime` and convert + # the duration (float) to an seconds + # (integer). + # See http://unix.stackexchange.com/a/89748 + local humanReadableDuration + if (( _P9K_COMMAND_DURATION > 3600 )); then + humanReadableDuration=$(TZ=GMT; strftime '%H:%M:%S' $(( int(rint(_P9K_COMMAND_DURATION)) ))) + elif (( _P9K_COMMAND_DURATION > 60 )); then + humanReadableDuration=$(TZ=GMT; strftime '%M:%S' $(( int(rint(_P9K_COMMAND_DURATION)) ))) + else + # If the command executed in seconds, print as float. + # Convert to float + if [[ "${POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION}" == "0" ]]; then + # If user does not want microseconds, then we need to convert + # the duration to an integer. + typeset -i humanReadableDuration + else + typeset -F ${POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION} humanReadableDuration + fi + humanReadableDuration=$_P9K_COMMAND_DURATION + fi + + if (( _P9K_COMMAND_DURATION >= POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD )); then + "$1_prompt_segment" "$0" "$2" "red" "yellow1" "${humanReadableDuration}" 'EXECUTION_TIME_ICON' + fi +} + +################################################################ +# Determine the unique path - this is needed for the +# truncate_to_unique strategy. +# +function getUniqueFolder() { + local trunc_path directory test_dir test_dir_length + local -a matching + local -a paths + local cur_path='/' + paths=(${(s:/:)1}) + for directory in ${paths[@]}; do + test_dir='' + for (( i=0; i < ${#directory}; i++ )); do + test_dir+="${directory:$i:1}" + matching=("$cur_path"/"$test_dir"*/) + if [[ ${#matching[@]} -eq 1 ]]; then + break + fi + done + trunc_path+="$test_dir/" + cur_path+="$directory/" + done + echo "${trunc_path: : -1}" +} + +################################################################ +# Dir: current working directory +# Parameters: +# * $1 Alignment: string - left|right +# * $2 Index: integer +set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" +set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~" +set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false +prompt_dir() { + # using $PWD instead of "$(print -P '%~')" to allow use of POWERLEVEL9K_DIR_PATH_ABSOLUTE + local current_path=$PWD # WAS: local current_path="$(print -P '%~')" + # check if the user wants to use absolute paths or "~" paths + [[ ${(L)POWERLEVEL9K_DIR_PATH_ABSOLUTE} != "true" ]] && current_path=${current_path//$HOME/"~"} + # declare all local variables + local paths directory test_dir test_dir_length trunc_path threshhold + # if we are not in "~" or "/", split the paths into an array and exclude "~" + (( ${#current_path} > 1 )) && paths=(${(s:/:)${current_path//"~\/"/}}) || paths=() + # only run the code if SHORTEN_DIR_LENGTH is set, or we are using the two strategies that don't rely on it. + if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_to_last" ]]; then + set_default POWERLEVEL9K_SHORTEN_DELIMITER "\u2026" + # convert delimiter from unicode to literal character, so that we can get the correct length later + local delim=$(echo -n $POWERLEVEL9K_SHORTEN_DELIMITER) + + case "$POWERLEVEL9K_SHORTEN_STRATEGY" in + truncate_absolute_chars) + if [ ${#current_path} -gt $(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#POWERLEVEL9K_SHORTEN_DELIMITER} )) ]; then + current_path=$POWERLEVEL9K_SHORTEN_DELIMITER${current_path:(-POWERLEVEL9K_SHORTEN_DIR_LENGTH)} + fi + ;; + truncate_middle) + # truncate characters from the middle of the path + current_path=$(truncatePath $current_path $POWERLEVEL9K_SHORTEN_DIR_LENGTH $POWERLEVEL9K_SHORTEN_DELIMITER "middle") + ;; + truncate_from_right) + # truncate characters from the right of the path + current_path=$(truncatePath "$current_path" $POWERLEVEL9K_SHORTEN_DIR_LENGTH $POWERLEVEL9K_SHORTEN_DELIMITER) + ;; + truncate_absolute) + # truncate all characters except the last POWERLEVEL9K_SHORTEN_DIR_LENGTH characters + if [ ${#current_path} -gt $(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#POWERLEVEL9K_SHORTEN_DELIMITER} )) ]; then + current_path=$POWERLEVEL9K_SHORTEN_DELIMITER${current_path:(-POWERLEVEL9K_SHORTEN_DIR_LENGTH)} + fi + ;; + truncate_to_last) + # truncate all characters before the current directory + current_path=${current_path##*/} + ;; + truncate_to_first_and_last) + if (( ${#current_path} > 1 )) && (( ${POWERLEVEL9K_SHORTEN_DIR_LENGTH} > 0 )); then + threshhold=$(( ${POWERLEVEL9K_SHORTEN_DIR_LENGTH} * 2)) + # if we are in "~", add it back into the paths array + [[ $current_path == '~'* ]] && paths=("~" "${paths[@]}") + if (( ${#paths} > $threshhold )); then + local num=$(( ${#paths} - ${POWERLEVEL9K_SHORTEN_DIR_LENGTH} )) + # repace the middle elements + for (( i=$POWERLEVEL9K_SHORTEN_DIR_LENGTH; i<$num; i++ )); do + paths[$i+1]=$POWERLEVEL9K_SHORTEN_DELIMITER + done + [[ $current_path != '~'* ]] && current_path="/" || current_path="" + current_path+="${(j:/:)paths}" + fi + fi + ;; + truncate_to_unique) + # for each parent path component find the shortest unique beginning + # characters sequence. Source: https://stackoverflow.com/a/45336078 + if (( ${#current_path} > 1 )); then # root and home are exceptions and won't have paths + # cheating here to retain ~ as home folder + local home_path="$(getUniqueFolder $HOME)" + trunc_path="$(getUniqueFolder $PWD)" + [[ $current_path == "~"* ]] && current_path="~${trunc_path//${home_path}/}" || current_path="/${trunc_path}" + fi + ;; + truncate_with_folder_marker) + if (( ${#paths} > 0 )); then # root and home are exceptions and won't have paths, so skip this + local last_marked_folder marked_folder + set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker" + + # Search for the folder marker in the parent directories and + # buildup a pattern that is removed from the current path + # later on. + for marked_folder in $(upsearch $POWERLEVEL9K_SHORTEN_FOLDER_MARKER); do + if [[ "$marked_folder" == "/" ]]; then + # If we reached root folder, stop upsearch. + trunc_path="/" + elif [[ "$marked_folder" == "$HOME" ]]; then + # If we reached home folder, stop upsearch. + trunc_path="~" + elif [[ "${marked_folder%/*}" == $last_marked_folder ]]; then + trunc_path="${trunc_path%/}/${marked_folder##*/}" + else + trunc_path="${trunc_path%/}/$POWERLEVEL9K_SHORTEN_DELIMITER/${marked_folder##*/}" + fi + last_marked_folder=$marked_folder + done + + # Replace the shortest possible match of the marked folder from + # the current path. + current_path=$trunc_path${current_path#${last_marked_folder}*} + fi + ;; + truncate_with_package_name) + local name repo_path package_path current_dir zero + + # Get the path of the Git repo, which should have the package.json file + if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == "true" ]]; then + # Get path from the root of the git repository to the current dir + local gitPath=$(git rev-parse --show-prefix) + # Remove trailing slash from git path, so that we can + # remove that git path from the pwd. + gitPath=${gitPath%/} + package_path=${$(pwd)%%$gitPath} + # Remove trailing slash + package_path=${package_path%/} + elif [[ $(git rev-parse --is-inside-git-dir 2> /dev/null) == "true" ]]; then + package_path=${$(pwd)%%/.git*} + fi + + # Replace the shortest possible match of the marked folder from + # the current path. Remove the amount of characters up to the + # folder marker from the left. Count only the visible characters + # in the path (this is done by the "zero" pattern; see + # http://stackoverflow.com/a/40855342/5586433). + local zero='%([BSUbfksu]|([FB]|){*})' + trunc_path=$(pwd) + # Then, find the length of the package_path string, and save the + # subdirectory path as a substring of the current directory's path from 0 + # to the length of the package path's string + subdirectory_path=$(truncatePath "${trunc_path:${#${(S%%)package_path//$~zero/}}}" $POWERLEVEL9K_SHORTEN_DIR_LENGTH $POWERLEVEL9K_SHORTEN_DELIMITER) + # Parse the 'name' from the package.json; if there are any problems, just + # print the file path + defined POWERLEVEL9K_DIR_PACKAGE_FILES || POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json) + + local pkgFile="unknown" + for file in "${POWERLEVEL9K_DIR_PACKAGE_FILES[@]}"; do + if [[ -f "${package_path}/${file}" ]]; then + pkgFile="${package_path}/${file}" + break; + fi + done + + local packageName=$(jq '.name' ${pkgFile} 2> /dev/null \ + || node -e 'console.log(require(process.argv[1]).name);' ${pkgFile} 2>/dev/null \ + || cat "${pkgFile}" 2> /dev/null | grep -m 1 "\"name\"" | awk -F ':' '{print $2}' | awk -F '"' '{print $2}' 2>/dev/null \ + ) + if [[ -n "${packageName}" ]]; then + # Instead of printing out the full path, print out the name of the package + # from the package.json and append the current subdirectory + current_path="`echo $packageName | tr -d '"'`$subdirectory_path" + fi + ;; + *) + if [[ $current_path != "~" ]]; then + current_path="$(print -P "%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c")" + fi + ;; + esac + fi + + # save state of path for highlighting and bold options + local path_opt=$current_path + + typeset -AH dir_states + dir_states=( + "DEFAULT" "FOLDER_ICON" + "HOME" "HOME_ICON" + "HOME_SUBFOLDER" "HOME_SUB_ICON" + "NOT_WRITABLE" "LOCK_ICON" + "ETC" "ETC_ICON" + ) + local state_path="$(print -P '%~')" + local current_state="DEFAULT" + if [[ $state_path == '/etc'* ]]; then + current_state='ETC' + elif [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then + current_state="NOT_WRITABLE" + elif [[ $state_path == '~' ]]; then + current_state="HOME" + elif [[ $state_path == '~'* ]]; then + current_state="HOME_SUBFOLDER" + fi + + # declare variables used for bold and state colors + local bld_on bld_off dir_state_foreground dir_state_user_foreground + # test if user wants the last directory printed in bold + if [[ "${(L)POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD}" == "true" ]]; then + bld_on="%B" + bld_off="%b" + else + bld_on="" + bld_off="" + fi + # determine is the user has set a last directory color + local dir_state_user_foreground=POWERLEVEL9K_DIR_${current_state}_FOREGROUND + local dir_state_foreground=${(P)dir_state_user_foreground} + [[ -z ${dir_state_foreground} ]] && dir_state_foreground="${DEFAULT_COLOR}" + + local dir_name base_name + # use ZSH substitution to get the dirname and basename instead of calling external functions + dir_name=${path_opt%/*} + base_name=${path_opt##*/} + + # if the user wants the last directory colored... + if [[ -n ${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND} ]]; then + # it the path is "/" or "~" + if [[ $path_opt == "/" || $path_opt == "~" ]]; then + current_path="${bld_on}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${current_path}${bld_off}" + else # has a subfolder + # test if dirname != basename - they are equal if we use truncate_to_last or truncate_absolute + if [[ $dir_name != $base_name ]]; then + current_path="${dir_name}/${bld_on}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${base_name}${bld_off}" + else + current_path="${bld_on}%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}${base_name}${bld_off}" + fi + fi + else # no coloring + # it the path is "/" or "~" + if [[ $path_opt == "/" || $path_opt == "~" ]]; then + current_path="${bld_on}${current_path}${bld_off}" + else # has a subfolder + # test if dirname != basename - they are equal if we use truncate_to_last or truncate_absolute + if [[ $dir_name != $base_name ]]; then + current_path="${dir_name}/${bld_on}${base_name}${bld_off}" + else + current_path="${bld_on}${base_name}${bld_off}" + fi + fi + fi + + # check if we need to omit the first character and only do it if we are not in "~" or "/" + if [[ "${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" && $path_opt != "/" && $path_opt != "~" ]]; then + current_path="${current_path[2,-1]}" + fi + + # check if the user wants the separator colored. + if [[ -n ${POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND} && $path_opt != "/" ]]; then + # because this contains color changing codes, it is easier to set a variable for what should be replaced + local repl="%F{$POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND}/%F{$dir_state_foreground}" + # escape the / with a \ + current_path=${current_path//\//$repl} + fi + + if [[ "${POWERLEVEL9K_DIR_PATH_SEPARATOR}" != "/" && $path_opt != "/" ]]; then + current_path=${current_path//\//$POWERLEVEL9K_DIR_PATH_SEPARATOR} + fi + + if [[ "${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}" != "~" && ! "${(L)POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then + # use :s to only replace the first occurance + current_path=${current_path:s/~/$POWERLEVEL9K_HOME_FOLDER_ABBREVIATION} + fi + + "$1_prompt_segment" "$0_${current_state}" "$2" "blue" "$DEFAULT_COLOR" "${current_path}" "${dir_states[$current_state]}" +} + +################################################################ +# Docker machine +prompt_docker_machine() { + local docker_machine="$DOCKER_MACHINE_NAME" + + if [[ -n "$docker_machine" ]]; then + "$1_prompt_segment" "$0" "$2" "magenta" "$DEFAULT_COLOR" "$docker_machine" 'SERVER_ICON' + fi +} + +################################################################ +# GO prompt +prompt_go_version() { + local go_version + local go_path + go_version=$(go version 2>/dev/null | sed -E "s/.*(go[0-9.]*).*/\1/") + go_path=$(go env GOPATH 2>/dev/null) + + if [[ -n "$go_version" && "${PWD##$go_path}" != "$PWD" ]]; then + "$1_prompt_segment" "$0" "$2" "green" "grey93" "$go_version" "GO_ICON" + fi +} + +################################################################ +# Command number (in local history) +prompt_history() { + "$1_prompt_segment" "$0" "$2" "grey50" "$DEFAULT_COLOR" '%h' +} + +################################################################ +# Detection for virtualization (systemd based systems only) +prompt_detect_virt() { + local virt=$(systemd-detect-virt 2> /dev/null) + if [[ "$virt" == "none" ]]; then + if [[ "$(ls -di / | grep -o 2)" != "2" ]]; then + virt="chroot" + fi + fi + + if [[ -n "${virt}" ]]; then + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "$virt" + fi +} + +################################################################ +# Test icons +prompt_icons_test() { + for key in ${(@k)icons}; do + # The lower color spectrum in ZSH makes big steps. Choosing + # the next color has enough contrast to read. + local random_color=$((RANDOM % 8)) + local next_color=$((random_color+1)) + "$1_prompt_segment" "$0" "$2" "$random_color" "$next_color" "$key" "$key" + done +} + +################################################################ +# Segment to display the current IP address +prompt_ip() { + if [[ "$OS" == "OSX" ]]; then + if defined POWERLEVEL9K_IP_INTERFACE; then + # Get the IP address of the specified interface. + ip=$(ipconfig getifaddr "$POWERLEVEL9K_IP_INTERFACE") + else + local interfaces callback + # Get network interface names ordered by service precedence. + interfaces=$(networksetup -listnetworkserviceorder | grep -o "Device:\s*[a-z0-9]*" | grep -o -E '[a-z0-9]*$') + callback='ipconfig getifaddr $item' + + ip=$(getRelevantItem "$interfaces" "$callback") + fi + else + if defined POWERLEVEL9K_IP_INTERFACE; then + # Get the IP address of the specified interface. + ip=$(ip -4 a show "$POWERLEVEL9K_IP_INTERFACE" | grep -o "inet\s*[0-9.]*" | grep -o -E "[0-9.]+") + else + local interfaces callback + # Get all network interface names that are up + interfaces=$(ip link ls up | grep -o -E ":\s+[a-z0-9]+:" | grep -v "lo" | grep -o -E "[a-z0-9]+") + callback='ip -4 a show $item | grep -o "inet\s*[0-9.]*" | grep -o -E "[0-9.]+"' + + ip=$(getRelevantItem "$interfaces" "$callback") + fi + fi + + if [[ -n "$ip" ]]; then + "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'NETWORK_ICON' + fi +} + +################################################################ +# Segment to display if VPN is active +set_default POWERLEVEL9K_VPN_IP_INTERFACE "tun" +# prompt if vpn active +prompt_vpn_ip() { + for vpn_iface in $(/sbin/ifconfig | grep -e ^"$POWERLEVEL9K_VPN_IP_INTERFACE" | cut -d":" -f1) + do + ip=$(/sbin/ifconfig "$vpn_iface" | grep -o "inet\s.*" | cut -d' ' -f2) + "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'VPN_ICON' + done +} + +################################################################ +# Segment to display laravel version +prompt_laravel_version() { + local laravel_version="$(php artisan --version 2> /dev/null)" + if [[ -n "${laravel_version}" && "${laravel_version}" =~ "Laravel Framework" ]]; then + # Strip out everything but the version + laravel_version="${laravel_version//Laravel Framework /}" + "$1_prompt_segment" "$0" "$2" "maroon" "white" "${laravel_version}" 'LARAVEL_ICON' + fi +} + +################################################################ +# Segment to display load +set_default POWERLEVEL9K_LOAD_WHICH 5 +prompt_load() { + local ROOT_PREFIX="${4}" + # The load segment can have three different states + local current_state="unknown" + local load_select=2 + local load_avg + local cores + + typeset -AH load_states + load_states=( + 'critical' 'red' + 'warning' 'yellow' + 'normal' 'green' + ) + + case "$POWERLEVEL9K_LOAD_WHICH" in + 1) + load_select=1 + ;; + 5) + load_select=2 + ;; + 15) + load_select=3 + ;; + esac + + case "$OS" in + OSX|BSD) + load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | sed -n ${load_select}p) + if [[ "$OS" == "OSX" ]]; then + cores=$(sysctl -n hw.logicalcpu) + else + cores=$(sysctl -n hw.ncpu) + fi + ;; + *) + load_avg=$(cut -d" " -f${load_select} ${ROOT_PREFIX}/proc/loadavg) + cores=$(nproc) + esac + + # Replace comma + load_avg=${load_avg//,/.} + + if [[ "$load_avg" -gt $((${cores} * 0.7)) ]]; then + current_state="critical" + elif [[ "$load_avg" -gt $((${cores} * 0.5)) ]]; then + current_state="warning" + else + current_state="normal" + fi + + "$1_prompt_segment" "${0}_${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" "$load_avg" 'LOAD_ICON' +} + +################################################################ +# Segment to diplay Node version +prompt_node_version() { + local node_version=$(node -v 2>/dev/null) + [[ -z "${node_version}" ]] && return + + "$1_prompt_segment" "$0" "$2" "green" "white" "${node_version:1}" 'NODE_ICON' +} + +################################################################ +# Segment to display Node version from NVM +# Only prints the segment if different than the default value +prompt_nvm() { + local node_version nvm_default + (( $+functions[nvm_version] )) || return + + node_version=$(nvm_version current) + [[ -z "${node_version}" || ${node_version} == "none" ]] && return + + nvm_default=$(nvm_version default) + [[ "$node_version" =~ "$nvm_default" ]] && return + + $1_prompt_segment "$0" "$2" "magenta" "black" "${node_version:1}" 'NODE_ICON' +} + +################################################################ +# Segment to display NodeEnv +prompt_nodeenv() { + local nodeenv_path="$NODE_VIRTUAL_ENV" + if [[ -n "$nodeenv_path" && "$NODE_VIRTUAL_ENV_DISABLE_PROMPT" != true ]]; then + local info="$(node -v)[$(basename "$nodeenv_path")]" + "$1_prompt_segment" "$0" "$2" "black" "green" "$info" 'NODE_ICON' + fi +} + +################################################################ +# Segment to print a little OS icon +prompt_os_icon() { + "$1_prompt_segment" "$0" "$2" "black" "white" "$OS_ICON" +} + +################################################################ +# Segment to display PHP version number +prompt_php_version() { + local php_version + php_version=$(php -v 2>&1 | grep -oe "^PHP\s*[0-9.]*") + + if [[ -n "$php_version" ]]; then + "$1_prompt_segment" "$0" "$2" "fuchsia" "grey93" "$php_version" + fi +} + +################################################################ +# Segment to display free RAM and used Swap +prompt_ram() { + local ROOT_PREFIX="${4}" + local base='' + local ramfree=0 + if [[ "$OS" == "OSX" ]]; then + # Available = Free + Inactive + # See https://support.apple.com/en-us/HT201538 + ramfree=$(vm_stat | grep "Pages free" | grep -o -E '[0-9]+') + ramfree=$((ramfree + $(vm_stat | grep "Pages inactive" | grep -o -E '[0-9]+'))) + # Convert pages into Bytes + ramfree=$(( ramfree * 4096 )) + else + if [[ "$OS" == "BSD" ]]; then + ramfree=$(grep 'avail memory' ${ROOT_PREFIX}/var/run/dmesg.boot | awk '{print $4}') + else + ramfree=$(grep -o -E "MemAvailable:\s+[0-9]+" ${ROOT_PREFIX}/proc/meminfo | grep -o -E "[0-9]+") + base='K' + fi + fi + + "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$(printSizeHumanReadable "$ramfree" $base)" 'RAM_ICON' +} + +################################################################ +# Segment to display rbenv information +# https://github.com/rbenv/rbenv#choosing-the-ruby-version +set_default POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW false +prompt_rbenv() { + if [[ -n "$RBENV_VERSION" ]]; then + "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "$RBENV_VERSION" 'RUBY_ICON' + elif [ $commands[rbenv] ]; then + local rbenv_version_name="$(rbenv version-name)" + local rbenv_global="$(rbenv global)" + if [[ "${rbenv_version_name}" != "${rbenv_global}" || "${POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW}" == "true" ]]; then + "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "$rbenv_version_name" 'RUBY_ICON' + fi + fi +} + +################################################################ +# Segment to display chruby information +# see https://github.com/postmodern/chruby/issues/245 for chruby_auto issue with ZSH +prompt_chruby() { + # Uses $RUBY_VERSION and $RUBY_ENGINE set by chruby + set_default POWERLEVEL9K_CHRUBY_SHOW_VERSION true + set_default POWERLEVEL9K_CHRUBY_SHOW_ENGINE true + local chruby_label="" + + if [[ "$POWERLEVEL9K_CHRUBY_SHOW_ENGINE" == true ]]; then + chruby_label+="$RUBY_ENGINE " + fi + if [[ "$POWERLEVEL9K_CHRUBY_SHOW_VERSION" == true ]]; then + chruby_label+="$RUBY_VERSION" + fi + + # Truncate trailing spaces + chruby_label="${chruby_label%"${chruby_label##*[![:space:]]}"}" + + # Don't show anything if the chruby did not change the default ruby + if [[ "$RUBY_ENGINE" != "" ]]; then + "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "${chruby_label}" 'RUBY_ICON' + fi +} + +################################################################ +# Segment to print an icon if user is root. +prompt_root_indicator() { + if [[ "$UID" -eq 0 ]]; then + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "" 'ROOT_ICON' + fi +} + +################################################################ +# Segment to display Rust version number +prompt_rust_version() { + local rust_version + rust_version=$(command rustc --version 2>/dev/null) + # Remove "rustc " (including the whitespace) from the beginning + # of the version string and remove everything after the next + # whitespace. This way we'll end up with only the version. + rust_version=${${rust_version/rustc /}%% *} + + if [[ -n "$rust_version" ]]; then + "$1_prompt_segment" "$0" "$2" "darkorange" "$DEFAULT_COLOR" "$rust_version" 'RUST_ICON' + fi +} + +# RSpec test ratio +prompt_rspec_stats() { + if [[ (-d app && -d spec) ]]; then + local code_amount tests_amount + code_amount=$(ls -1 app/**/*.rb | wc -l) + tests_amount=$(ls -1 spec/**/*.rb | wc -l) + + build_test_stats "$1" "$0" "$2" "$code_amount" "$tests_amount" "RSpec" 'TEST_ICON' + fi +} + +################################################################ +# Segment to display Ruby Version Manager information +prompt_rvm() { + local version_and_gemset=${rvm_env_string/ruby-} + + if [[ -n "$version_and_gemset" ]]; then + "$1_prompt_segment" "$0" "$2" "grey35" "$DEFAULT_COLOR" "$version_and_gemset" 'RUBY_ICON' + fi +} + +################################################################ +# Segment to display SSH icon when connected +prompt_ssh() { + if [[ -n "$SSH_CLIENT" ]] || [[ -n "$SSH_TTY" ]]; then + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "" 'SSH_ICON' + fi +} + +################################################################ +# Status: When an error occur, return the error code, or a cross icon if option is set +# Display an ok icon when no error occur, or hide the segment if option is set to false +# +set_default POWERLEVEL9K_STATUS_CROSS false +set_default POWERLEVEL9K_STATUS_OK true +set_default POWERLEVEL9K_STATUS_SHOW_PIPESTATUS true +set_default POWERLEVEL9K_STATUS_HIDE_SIGNAME false +# old options, retro compatibility +set_default POWERLEVEL9K_STATUS_VERBOSE true +set_default POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE false + +exit_code_or_status() { + local ec=$1 + if [[ "$POWERLEVEL9K_STATUS_HIDE_SIGNAME" = true ]]; then + echo "$ec" + elif (( ec <= 128 )); then + echo "$ec" + else + local sig=$(( ec - 128 )) + local idx=$(( sig + 1 )) + echo "SIG${signals[$idx]}(${sig})" + fi +} + +prompt_status() { + local ec_text + local ec_sum + local ec + + if [[ $POWERLEVEL9K_STATUS_SHOW_PIPESTATUS == true ]]; then + if (( $#RETVALS > 1 )); then + ec_text=$(exit_code_or_status "${RETVALS[1]}") + ec_sum=${RETVALS[1]} + else + ec_text=$(exit_code_or_status "${RETVAL}") + ec_sum=${RETVAL} + fi + + for ec in "${(@)RETVALS[2,-1]}"; do + ec_text="${ec_text}|$(exit_code_or_status "$ec")" + ec_sum=$(( $ec_sum + $ec )) + done + else + # We use RETVAL instead of the right-most RETVALS item because + # PIPE_FAIL may be set. + ec_text=$(exit_code_or_status "${RETVAL}") + ec_sum=${RETVAL} + fi + + if (( ec_sum > 0 )); then + if [[ "$POWERLEVEL9K_STATUS_CROSS" == false && "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then + "$1_prompt_segment" "$0_ERROR" "$2" "red" "yellow1" "$ec_text" 'CARRIAGE_RETURN_ICON' + else + "$1_prompt_segment" "$0_ERROR" "$2" "$DEFAULT_COLOR" "red" "" 'FAIL_ICON' + fi + elif [[ "$POWERLEVEL9K_STATUS_OK" == true ]] && [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true || "$POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE" == true ]]; then + "$1_prompt_segment" "$0_OK" "$2" "$DEFAULT_COLOR" "green" "" 'OK_ICON' + fi +} + +################################################################ +# Segment to display Swap information +prompt_swap() { + local ROOT_PREFIX="${4}" + local swap_used=0 + local base='' + + if [[ "$OS" == "OSX" ]]; then + local raw_swap_used + raw_swap_used=$(sysctl vm.swapusage | grep -o "used\s*=\s*[0-9,.A-Z]*" | grep -o "[0-9,.A-Z]*$") + + typeset -F 2 swap_used + swap_used=${$(echo $raw_swap_used | grep -o "[0-9,.]*")//,/.} + # Replace comma + swap_used=${swap_used//,/.} + + base=$(echo "$raw_swap_used" | grep -o "[A-Z]*$") + else + swap_total=$(grep -o -E "SwapTotal:\s+[0-9]+" ${ROOT_PREFIX}/proc/meminfo | grep -o -E "[0-9]+") + swap_free=$(grep -o -E "SwapFree:\s+[0-9]+" ${ROOT_PREFIX}/proc/meminfo | grep -o -E "[0-9]+") + swap_used=$(( swap_total - swap_free )) + base='K' + fi + + "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$(printSizeHumanReadable "$swap_used" $base)" 'SWAP_ICON' +} + +################################################################ +# Symfony2-PHPUnit test ratio +prompt_symfony2_tests() { + if [[ (-d src && -d app && -f app/AppKernel.php) ]]; then + local code_amount tests_amount + code_amount=$(ls -1 src/**/*.php | grep -vc Tests) + tests_amount=$(ls -1 src/**/*.php | grep -c Tests) + + build_test_stats "$1" "$0" "$2" "$code_amount" "$tests_amount" "SF2" 'TEST_ICON' + fi +} + +################################################################ +# Segment to display Symfony2-Version +prompt_symfony2_version() { + if [[ -f app/bootstrap.php.cache ]]; then + local symfony2_version + symfony2_version=$(grep " VERSION " app/bootstrap.php.cache | sed -e 's/[^.0-9]*//g') + "$1_prompt_segment" "$0" "$2" "grey35" "$DEFAULT_COLOR" "$symfony2_version" 'SYMFONY_ICON' + fi +} + +################################################################ +# Show a ratio of tests vs code +build_test_stats() { + local code_amount="$4" + local tests_amount="$5"+0.00001 + local headline="$6" + + # Set float precision to 2 digits: + typeset -F 2 ratio + local ratio=$(( (tests_amount/code_amount) * 100 )) + + (( ratio >= 75 )) && "$1_prompt_segment" "${2}_GOOD" "$3" "cyan" "$DEFAULT_COLOR" "$headline: $ratio%%" "$6" + (( ratio >= 50 && ratio < 75 )) && "$1_prompt_segment" "$2_AVG" "$3" "yellow" "$DEFAULT_COLOR" "$headline: $ratio%%" "$6" + (( ratio < 50 )) && "$1_prompt_segment" "$2_BAD" "$3" "red" "$DEFAULT_COLOR" "$headline: $ratio%%" "$6" +} + +################################################################ +# System time +prompt_time() { + set_default POWERLEVEL9K_TIME_FORMAT "%D{%H:%M:%S}" + + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "$POWERLEVEL9K_TIME_FORMAT" "TIME_ICON" +} + +################################################################ +# System date +prompt_date() { + set_default POWERLEVEL9K_DATE_FORMAT "%D{%d.%m.%y}" + + "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "$POWERLEVEL9K_DATE_FORMAT" "DATE_ICON" +} + +################################################################ +# todo.sh: shows the number of tasks in your todo.sh file +prompt_todo() { + if $(hash todo.sh 2>&-); then + count=$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }') + if [[ "$count" = <-> ]]; then + "$1_prompt_segment" "$0" "$2" "grey50" "$DEFAULT_COLOR" "$count" 'TODO_ICON' + fi + fi +} + +################################################################ +# VCS segment: shows the state of your repository, if you are in a folder under +# version control +set_default POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND "red" +# Default: Just display the first 8 characters of our changeset-ID. +set_default POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH "8" +powerlevel9k_vcs_init() { + if [[ -n "$POWERLEVEL9K_CHANGESET_HASH_LENGTH" ]]; then + POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH="$POWERLEVEL9K_CHANGESET_HASH_LENGTH" + fi + + # Load VCS_INFO + autoload -Uz vcs_info + + VCS_WORKDIR_DIRTY=false + VCS_WORKDIR_HALF_DIRTY=false + + # The vcs segment can have three different states - defaults to 'clean'. + typeset -gAH vcs_states + vcs_states=( + 'clean' 'green' + 'modified' 'yellow' + 'untracked' 'green' + ) + + VCS_CHANGESET_PREFIX='' + if [[ "$POWERLEVEL9K_SHOW_CHANGESET" == true ]]; then + VCS_CHANGESET_PREFIX="$(print_icon 'VCS_COMMIT_ICON')%0.$POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH""i " + fi + + zstyle ':vcs_info:*' enable git hg svn + zstyle ':vcs_info:*' check-for-changes true + + VCS_DEFAULT_FORMAT="$VCS_CHANGESET_PREFIX%b%c%u%m" + zstyle ':vcs_info:*' formats "$VCS_DEFAULT_FORMAT" + + zstyle ':vcs_info:*' actionformats "%b %F{${POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND}}| %a%f" + + zstyle ':vcs_info:*' stagedstr " $(print_icon 'VCS_STAGED_ICON')" + zstyle ':vcs_info:*' unstagedstr " $(print_icon 'VCS_UNSTAGED_ICON')" + + defined POWERLEVEL9K_VCS_GIT_HOOKS || POWERLEVEL9K_VCS_GIT_HOOKS=(vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname) + zstyle ':vcs_info:git*+set-message:*' hooks $POWERLEVEL9K_VCS_GIT_HOOKS + defined POWERLEVEL9K_VCS_HG_HOOKS || POWERLEVEL9K_VCS_HG_HOOKS=(vcs-detect-changes) + zstyle ':vcs_info:hg*+set-message:*' hooks $POWERLEVEL9K_VCS_HG_HOOKS + defined POWERLEVEL9K_VCS_SVN_HOOKS || POWERLEVEL9K_VCS_SVN_HOOKS=(vcs-detect-changes svn-detect-changes) + zstyle ':vcs_info:svn*+set-message:*' hooks $POWERLEVEL9K_VCS_SVN_HOOKS + + # For Hg, only show the branch name + zstyle ':vcs_info:hg*:*' branchformat "$(print_icon 'VCS_BRANCH_ICON')%b" + # The `get-revision` function must be turned on for dirty-check to work for Hg + zstyle ':vcs_info:hg*:*' get-revision true + zstyle ':vcs_info:hg*:*' get-bookmarks true + zstyle ':vcs_info:hg*+gen-hg-bookmark-string:*' hooks hg-bookmarks + + # For svn, only + # TODO fix the %b (branch) format for svn. Using %b breaks + # color-encoding of the foreground for the rest of the powerline. + zstyle ':vcs_info:svn*:*' formats "$VCS_CHANGESET_PREFIX%c%u" + zstyle ':vcs_info:svn*:*' actionformats "$VCS_CHANGESET_PREFIX%c%u %F{${POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND}}| %a%f" + + if [[ "$POWERLEVEL9K_SHOW_CHANGESET" == true ]]; then + zstyle ':vcs_info:*' get-revision true + fi +} + +################################################################ +# Segment to show VCS information +prompt_vcs() { + VCS_WORKDIR_DIRTY=false + VCS_WORKDIR_HALF_DIRTY=false + local current_state="" + + # Actually invoke vcs_info manually to gather all information. + vcs_info + local vcs_prompt="${vcs_info_msg_0_}" + + if [[ -n "$vcs_prompt" ]]; then + if [[ "$VCS_WORKDIR_DIRTY" == true ]]; then + # $vcs_visual_identifier gets set in +vi-vcs-detect-changes in functions/vcs.zsh, + # as we have there access to vcs_info internal hooks. + current_state='modified' + else + if [[ "$VCS_WORKDIR_HALF_DIRTY" == true ]]; then + current_state='untracked' + else + current_state='clean' + fi + fi + "$1_prompt_segment" "${0}_${(U)current_state}" "$2" "${vcs_states[$current_state]}" "$DEFAULT_COLOR" "$vcs_prompt" "$vcs_visual_identifier" + fi +} + +################################################################ +# Vi Mode: show editing mode (NORMAL|INSERT) +set_default POWERLEVEL9K_VI_INSERT_MODE_STRING "INSERT" +set_default POWERLEVEL9K_VI_COMMAND_MODE_STRING "NORMAL" +prompt_vi_mode() { + case ${KEYMAP} in + vicmd) + "$1_prompt_segment" "$0_NORMAL" "$2" "$DEFAULT_COLOR" "white" "$POWERLEVEL9K_VI_COMMAND_MODE_STRING" + ;; + main|viins|*) + if [[ -z $POWERLEVEL9K_VI_INSERT_MODE_STRING ]]; then return; fi + "$1_prompt_segment" "$0_INSERT" "$2" "$DEFAULT_COLOR" "blue" "$POWERLEVEL9K_VI_INSERT_MODE_STRING" + ;; + esac +} + +################################################################ +# Virtualenv: current working virtualenv +# More information on virtualenv (Python): +# https://virtualenv.pypa.io/en/latest/ +prompt_virtualenv() { + local virtualenv_path="$VIRTUAL_ENV" + if [[ -n "$virtualenv_path" && "$VIRTUAL_ENV_DISABLE_PROMPT" != true ]]; then + "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$(basename "$virtualenv_path")" 'PYTHON_ICON' + fi +} + +################################################################ +# Segment to display pyenv information +# https://github.com/pyenv/pyenv#choosing-the-python-version +set_default POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW false +prompt_pyenv() { + if [[ -n "$PYENV_VERSION" ]]; then + "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$PYENV_VERSION" 'PYTHON_ICON' + elif [ $commands[pyenv] ]; then + local pyenv_version_name="$(pyenv version-name)" + local pyenv_global="system" + local pyenv_root="$(pyenv root)" + if [[ -f "${pyenv_root}/version" ]]; then + pyenv_global="$(pyenv version-file-read ${pyenv_root}/version)" + fi + if [[ "${pyenv_version_name}" != "${pyenv_global}" || "${POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW}" == "true" ]]; then + "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$pyenv_version_name" 'PYTHON_ICON' + fi + fi +} + +################################################################ +# Display openfoam information +prompt_openfoam() { + local wm_project_version="$WM_PROJECT_VERSION" + local wm_fork="$WM_FORK" + if [[ -n "$wm_project_version" ]] && [[ -z "$wm_fork" ]] ; then + "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "OF: $(basename "$wm_project_version")" + elif [[ -n "$wm_project_version" ]] && [[ -n "$wm_fork" ]] ; then + "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "F-X: $(basename "$wm_project_version")" + fi +} + +################################################################ +# Segment to display Swift version +prompt_swift_version() { + # Get the first number as this is probably the "main" version number.. + local swift_version=$(swift --version 2>/dev/null | grep -o -E "[0-9.]+" | head -n 1) + [[ -z "${swift_version}" ]] && return + + "$1_prompt_segment" "$0" "$2" "magenta" "white" "${swift_version}" 'SWIFT_ICON' +} + +################################################################ +# dir_writable: Display information about the user's permission to write in the current directory +prompt_dir_writable() { + if [[ ! -w "$PWD" ]]; then + "$1_prompt_segment" "$0_FORBIDDEN" "$2" "red" "yellow1" "" 'LOCK_ICON' + fi +} + +################################################################ +# Kubernetes Current Context/Namespace +prompt_kubecontext() { + local kubectl_version="$(kubectl version --client 2>/dev/null)" + + if [[ -n "$kubectl_version" ]]; then + # Get the current Kuberenetes context + local cur_ctx=$(kubectl config view -o=jsonpath='{.current-context}') + cur_namespace="$(kubectl config view -o=jsonpath="{.contexts[?(@.name==\"${cur_ctx}\")].context.namespace}")" + # If the namespace comes back empty set it default. + if [[ -z "${cur_namespace}" ]]; then + cur_namespace="default" + fi + + local k8s_final_text="" + + if [[ "$cur_ctx" == "$cur_namespace" ]]; then + # No reason to print out the same identificator twice + k8s_final_text="$cur_ctx" + else + k8s_final_text="$cur_ctx/$cur_namespace" + fi + + "$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_final_text" "KUBERNETES_ICON" + fi +} + +################################################################ +# Dropbox status +prompt_dropbox() { + # The first column is just the directory, so cut it + local dropbox_status="$(dropbox-cli filestatus . | cut -d\ -f2-)" + + # Only show if the folder is tracked and dropbox is running + if [[ "$dropbox_status" != 'unwatched' && "$dropbox_status" != "isn't running!" ]]; then + # If "up to date", only show the icon + if [[ "$dropbox_status" =~ 'up to date' ]]; then + dropbox_status="" + fi + + "$1_prompt_segment" "$0" "$2" "white" "blue" "$dropbox_status" "DROPBOX_ICON" + fi +} + +# print Java version number +prompt_java_version() { + local java_version + # Stupid: Java prints its version on STDERR. + # The first version ouput will print nothing, we just + # use it to transport whether the command was successful. + # If yes, we parse the version string (and need to + # redirect the stderr to stdout to make the pipe work). + java_version=$(java -version 2>/dev/null && java -fullversion 2>&1 | cut -d '"' -f 2) + + if [[ -n "$java_version" ]]; then + "$1_prompt_segment" "$0" "$2" "red" "white" "$java_version" "JAVA_ICON" + fi +} + +################################################################ +# Prompt processing and drawing +################################################################ +# Main prompt +build_left_prompt() { + local index=1 + local element + for element in "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[@]}"; do + # Remove joined information in direct calls + element=${element%_joined} + + # Check if it is a custom command, otherwise interpet it as + # a prompt. + if [[ $element[0,7] =~ "custom_" ]]; then + "prompt_custom" "left" "$index" $element[8,-1] + else + "prompt_$element" "left" "$index" + fi + + index=$((index + 1)) + done + + left_prompt_end +} + +# Right prompt +build_right_prompt() { + local index=1 + local element + for element in "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[@]}"; do + # Remove joined information in direct calls + element=${element%_joined} + + # Check if it is a custom command, otherwise interpet it as + # a prompt. + if [[ $element[0,7] =~ "custom_" ]]; then + "prompt_custom" "right" "$index" $element[8,-1] + else + "prompt_$element" "right" "$index" + fi + + index=$((index + 1)) + done + + # Clear to the end of the line + echo -n "%E" +} + +powerlevel9k_preexec() { + _P9K_TIMER_START=$EPOCHREALTIME +} + +set_default POWERLEVEL9K_PROMPT_ADD_NEWLINE false +powerlevel9k_prepare_prompts() { + # Return values. These need to be global, because + # they are used in prompt_status. Also, we need + # to get the return value of the last command at + # very first in this function. Do not move the + # lines down, otherwise the last command is not + # what you expected it to be. + RETVAL=$? + RETVALS=( "$pipestatus[@]" ) + + local RPROMPT_SUFFIX RPROMPT_PREFIX + _P9K_COMMAND_DURATION=$((EPOCHREALTIME - _P9K_TIMER_START)) + + # Reset start time + _P9K_TIMER_START=0x7FFFFFFF + + if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then + PROMPT='$(print_icon 'MULTILINE_FIRST_PROMPT_PREFIX')%f%b%k$(build_left_prompt) +$(print_icon 'MULTILINE_LAST_PROMPT_PREFIX')' + if [[ "$POWERLEVEL9K_RPROMPT_ON_NEWLINE" != true ]]; then + # The right prompt should be on the same line as the first line of the left + # prompt. To do so, there is just a quite ugly workaround: Before zsh draws + # the RPROMPT, we advise it, to go one line up. At the end of RPROMPT, we + # advise it to go one line down. See: + # http://superuser.com/questions/357107/zsh-right-justify-in-ps1 + local LC_ALL="" LC_CTYPE="en_US.UTF-8" # Set the right locale to protect special characters + RPROMPT_PREFIX='%{'$'\e[1A''%}' # one line up + RPROMPT_SUFFIX='%{'$'\e[1B''%}' # one line down + else + RPROMPT_PREFIX='' + RPROMPT_SUFFIX='' + fi + else + PROMPT='%f%b%k$(build_left_prompt)' + RPROMPT_PREFIX='' + RPROMPT_SUFFIX='' + fi + + if [[ "$POWERLEVEL9K_DISABLE_RPROMPT" != true ]]; then + RPROMPT="${RPROMPT_PREFIX}"'%f%b%k$(build_right_prompt)%{$reset_color%}'"${RPROMPT_SUFFIX}" + fi + +local NEWLINE=' +' + + if [[ $POWERLEVEL9K_PROMPT_ADD_NEWLINE == true ]]; then + NEWLINES="" + repeat ${POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT:-1} { NEWLINES+=$NEWLINE } + PROMPT="$NEWLINES$PROMPT" + fi + + # Allow iTerm integration to work + [[ $ITERM_SHELL_INTEGRATION_INSTALLED == "Yes" ]] && PROMPT="%{$(iterm2_prompt_mark)%}$PROMPT" +} + +zle-keymap-select () { + zle reset-prompt + zle -R +} + +set_default POWERLEVEL9K_IGNORE_TERM_COLORS false +set_default POWERLEVEL9K_IGNORE_TERM_LANG false + +prompt_powerlevel9k_setup() { + # The value below was set to better support 32-bit CPUs. + # It's the maximum _signed_ integer value on 32-bit CPUs. + # Please don't change it until 19 January of 2038. ;) + + # Disable false display of command execution time + _P9K_TIMER_START=0x7FFFFFFF + + # The prompt function will set these prompt_* options after the setup function + # returns. We need prompt_subst so we can safely run commands in the prompt + # without them being double expanded and we need prompt_percent to expand the + # common percent escape sequences. + prompt_opts=(cr percent sp subst) + + # Borrowed from promptinit, sets the prompt options in case the theme was + # not initialized via promptinit. + setopt noprompt{bang,cr,percent,sp,subst} "prompt${^prompt_opts[@]}" + + # Display a warning if the terminal does not support 256 colors + termColors + + # If the terminal `LANG` is set to `C`, this theme will not work at all. + if [[ $POWERLEVEL9K_IGNORE_TERM_LANG == false ]]; then + local term_lang + term_lang=$(echo $LANG) + if [[ $term_lang == 'C' ]]; then + print -P "\t%F{red}WARNING!%f Your terminal's 'LANG' is set to 'C', which breaks this theme!" + print -P "\t%F{red}WARNING!%f Please set your 'LANG' to a UTF-8 language, like 'en_US.UTF-8'" + print -P "\t%F{red}WARNING!%f _before_ loading this theme in your \~\.zshrc. Putting" + print -P "\t%F{red}WARNING!%f %F{blue}export LANG=\"en_US.UTF-8\"%f at the top of your \~\/.zshrc is sufficient." + fi + fi + + defined POWERLEVEL9K_LEFT_PROMPT_ELEMENTS || POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir vcs) + defined POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS || POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs history time) + + # Display a warning if deprecated segments are in use. + typeset -AH deprecated_segments + # old => new + deprecated_segments=( + 'longstatus' 'status' + ) + print_deprecation_warning deprecated_segments + + # initialize colors + autoload -U colors && colors + + if segment_in_use "vcs"; then + powerlevel9k_vcs_init + fi + + # initialize timing functions + zmodload zsh/datetime + + # Initialize math functions + zmodload zsh/mathfunc + + # initialize hooks + autoload -Uz add-zsh-hook + + # prepare prompts + add-zsh-hook precmd powerlevel9k_prepare_prompts + add-zsh-hook preexec powerlevel9k_preexec + + zle -N zle-keymap-select +} + +prompt_powerlevel9k_teardown() { + add-zsh-hook -D precmd powerlevel9k_\* + add-zsh-hook -D preexec powerlevel9k_\* + PROMPT='%m%# ' + RPROMPT= +} + +prompt_powerlevel9k_setup "$@" diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/prompt_powerlevel9k_setup b/config/zsh/oh-my-zsh-custom/powerlevel9k/prompt_powerlevel9k_setup new file mode 120000 index 0000000..311575f --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/prompt_powerlevel9k_setup @@ -0,0 +1 @@ +powerlevel9k.zsh-theme \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test-bsd-vm/Vagrantfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-bsd-vm/Vagrantfile new file mode 100644 index 0000000..7df512a --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-bsd-vm/Vagrantfile @@ -0,0 +1,87 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure("2") do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://atlas.hashicorp.com/search. + config.vm.box = "freebsd/FreeBSD-11.0-STABLE" + + # Bootstrap + config.vm.provision :shell, path: "bootstrap-zero.sh", privileged: true + config.vm.provision :shell, path: "bootstrap.sh", privileged: false + config.vm.provision :shell, path: "../test-vm-providers/plain.sh", privileged: false + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + # config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + config.vm.network "private_network", ip: "192.168.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + #config.vm.network "public_network" + + # The BSD base box does not define a MAC address. Whysoever. + config.vm.base_mac = "8AAB4975994A" + + # There is no BASH for root on BSD. We need to set another shell. + # See https://www.freebsd.org/doc/en/articles/linux-users/shells.html + config.ssh.shell = "/bin/sh" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + config.vm.synced_folder "..", "/vagrant_data", type: "nfs" + config.vm.synced_folder ".", "/vagrant", type: "nfs" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + config.vm.provider "virtualbox" do |vb| + + # Change name to "powerlevel9k-bsd" + vb.name = "powerlevel9k-bsd" + + # Display the VirtualBox GUI when booting the machine + #vb.gui = true + + # Customize the amount of memory on the VM: + vb.memory = "256" + end + + # View the documentation for the provider you are using for more + # information on available options. + + # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies + # such as FTP and Heroku are also available. See the documentation at + # https://docs.vagrantup.com/v2/push/atlas.html for more information. + # config.push.define "atlas" do |push| + # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" + # end + + # Enable provisioning with a shell script. Additional provisioners such as + # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the + # documentation for more information about their specific syntax and use. + # config.vm.provision "shell", inline: <<-SHELL + # apt-get update + # apt-get install -y apache2 + # SHELL +end diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test-bsd-vm/bootstrap-zero.sh b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-bsd-vm/bootstrap-zero.sh new file mode 100644 index 0000000..35dcd7f --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-bsd-vm/bootstrap-zero.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +pkg install -y sudo \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test-bsd-vm/bootstrap.sh b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-bsd-vm/bootstrap.sh new file mode 100644 index 0000000..ba27ffb --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-bsd-vm/bootstrap.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# Install ZSH +sudo pkg install -y zsh +sudo chsh -s `which zsh` vagrant +sudo ln -s /usr/local/bin/zsh /usr/bin/zsh + +# Install git +sudo pkg install -y git +# Install mercurial +sudo pkg install -y mercurial +# Install subversion +sudo pkg install -y subversion \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test-in-docker b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-in-docker new file mode 100755 index 0000000..0ed1254 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-in-docker @@ -0,0 +1,200 @@ +#!/usr/bin/env zsh + +set -eu + +# The default ZSH to use; it can just be the first few characters. +# This should be the oldest version we support. +default_version='4.' + +setopt extended_glob glob_subst numeric_glob_sort +setopt warn_create_global warn_nested_var 2> /dev/null +cd "${${(%):-%x}:A:h}" + +# TODO: Crazy Logic to munge TERM to something supported in Ubuntu 14.04 +term=screen-256color + +# Note: If versions and frameworks looks complicated, it isn't that bad... +# ...see Modifiers in zshexpn(1) for details. + +# List of ZSH versions +typeset -aU versions +versions=( docker/base-*/Dockerfile(N.on:h:t:s/base-//) ) +typeset -r versions + +# List of frameworks +typeset -aU frameworks +frameworks=( docker/*/Dockerfile(N.on:h:t) ) +for i in {$#frameworks..1}; do + # Remove all base entries + [[ "${frameworks[$i]}" == base-* ]] && frameworks[$i]=() +done +typeset -r frameworks + +# Known Issues +typeset -A known_issues +known_issues["4.3.11-antigen"]="Antigen commands that need git won't work; it needs a newer version of git." +known_issues["4.3.11-zim"]="BROKEN: Zim wants ZSH 5.2 or newer." +known_issues["5.0.3-zim"]="DEPRECATED: Zim wants ZSH 5.2 or newer." +known_issues["5.1.1-zim"]="DEPRECATED: Zim wants ZSH 5.2 or newer." +known_issues["4.3.11-zulu"]="Zulu doesn't work; it needs a newer version of git." +typeset -r known_issues + +err() +{ + print -P "%F{red}Error:%f $*" + exit 2 +} + +resolve_framework() { + local f=$1 found + found=${frameworks[(In:-1:)$f*]} + if (( found <= $#frameworks )); then + echo "${frameworks[$found]}" + fi +} + +resolve_version() { + local v=$1 found + found=${versions[(In:-1:)$v*]} + if (( found <= $#versions )); then + echo "${versions[$found]}" + fi +} + +check_for_known_issues() { + local version="$1" + local framework="$2" + local name="${version}-${framework}" + + if (( ${+known_issues["$name"]} )); then + echo + print -P "%F{red}Known Issue: %F{yellow}${known_issues["$name"]}%f" + echo + fi +} + +cmd() { + if (( dry_run )); then + echo "${(@q)*}" 1>&2 + else + "${(@)*}" + fi +} + +build_and_run() { + local version="$1" + local framework="$2" + local name="${version}-${framework}" + + check_for_known_issues "$version" "$framework" + + print -P "%F{green}Preparing containers...%f" + + echo -n "p9k:base-${version}: " + cmd docker build \ + --quiet \ + --tag "p9k:base-${version}" \ + --file "docker/base-${version}/Dockerfile" \ + . + + echo -n "p9k:${version}-${framework}: " + cmd docker build \ + --quiet \ + --build-arg="base=base-${version}" \ + --tag "p9k:${version}-${framework}" \ + --file "docker/${framework}/Dockerfile" \ + . + + print -P "%F{green}Starting ${name} container...%f" + cmd docker run \ + --rm \ + --interactive \ + --tty \ + --hostname="${name//./_}" \ + --env="TERM=${term}" \ + "p9k:${version}-${framework}" +} + +show_help() { + local f v + echo "Usage: ${(%):-%x} |--list" + echo + echo "Loads up a docker image with powershell9k configured in " + echo + echo " -f --frameworks Lists all available frameworks, newline separated." + echo " -v --versions Lists all available ZSH versions, newline separated." + echo " -z --zsh VER Uses ZSH with version VER." + echo " -n --dry-run Just prints the docker commands that would be run." + echo " --help You're soaking in it." + echo + echo "ZSH versions:" + for v in "${(@)versions}"; do + echo " $v" + done + echo + echo "Framework containers:" + for f in "${(@)frameworks}"; do + echo " $f" + done +} + +# No arguments +if (( $# == 0 )); then + show_help + exit +fi + +# Parse flags and such. +asked_for_version=$default_version +asked_for_framework= +dry_run=0 +while (( $# > 0 )); do + case "$1" in + -f | --frameworks ) + print -l "${(@)frameworks}" + exit + ;; + -v | --versions ) + print -l "${(@)versions}" + exit + ;; + -z | --zsh ) + shift + asked_for_version=$1 + ;; + -n | --dry-run ) dry_run=1 ;; + -h | --help ) + show_help + exit + ;;; + -* ) + err "Unknown option ${1}" + show_help + exit 1 + ;; + * ) + if [[ -z "$asked_for_framework" ]]; then + asked_for_framework=$1 + else + err "You can only specify one framework at a time; you already specified '${asked_for_framework}'" + fi + ;; + esac + shift +done + +typeset -r asked_for_version asked_for_framework + +typeset -r use_version="$(resolve_version "${asked_for_version}")" +if [[ -z "$use_version" ]]; then + err "No such ZSH version '${asked_for_version}'" +fi + +typeset -r use_framework="$(resolve_framework "${asked_for_framework}")" +if [[ -z "$use_framework" ]]; then + err "No such framework '${asked_for_framework}'" +fi + +build_and_run "$use_version" "$use_framework" + +# EOF diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm-providers/plain.sh b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm-providers/plain.sh new file mode 100644 index 0000000..b827a0c --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm-providers/plain.sh @@ -0,0 +1,9 @@ +#!/usr/bin/zsh + +echo 'LANG=en_US.UTF-8' >! ~/.zshrc +echo 'source /vagrant_data/powerlevel9k.zsh-theme' >> ~/.zshrc + +echo 'echo "Have a look at the ~/p9k folder for prepared test setups."' >> ~/.zshrc + +# setup environment +/vagrant_data/test-vm-providers/setup-environment.sh \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm-providers/setup-environment.sh b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm-providers/setup-environment.sh new file mode 100755 index 0000000..0e8beb6 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm-providers/setup-environment.sh @@ -0,0 +1,44 @@ +#!/usr/bin/zsh + +OLDPWD="$(pwd)" +cd $HOME + +TESTFOLDER="${HOME}/p9k" +mkdir -p $TESTFOLDER +cd $TESTFOLDER + +# Make a deep test folder +mkdir -p deep-folder/1/12/123/1234/12345/123456/1234567/123455678/123456789 + +# Make a git repo +mkdir git-repo +cd git-repo +git config --global user.email "test@powerlevel9k.theme" +git config --global user.name "Testing Tester" +git init +echo "TEST" >> testfile +git add testfile +git commit -m "Initial commit" +cd $TESTFOLDER + +# Make a Mercurial repo +mkdir hg-repo +cd hg-repo +export HGUSER="Test bot " +hg init +echo "TEST" >> testfile +hg add testfile +hg ci -m "Initial commit" +cd $TESTFOLDER + +# Setup a SVN folder +svnadmin create ~/.svn-repo +mkdir svn-repo +svn checkout "file://${HOME}/.svn-repo" "svn-repo" +cd svn-repo +echo "TEST" >> testfile +svn add testfile +svn commit -m "Initial commit" +cd $TESTFOLDER + +cd $OLDPWD \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/README.md b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/README.md new file mode 100644 index 0000000..9f0861e --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/README.md @@ -0,0 +1,25 @@ +# Test-VM for powerlevel9k + +In this virtual machine you will find a recent ubuntu with preinstalled ZSH, oh-my-zsh, antigen, prezto and - of course - powerlevel9k. The main use-case is to test the powerlevel9k theme. + +## Installation + +In order to run this virtual machine, you need [vagrant](https://www.vagrantup.com/) and [VirtualBox](http://www.virtualbox.org/). + +## Running + +`vagrant` is a quite easy to use command line tool to configure a virtual machine. To fire the machine up, just run `vagrant up`. At the first run, it will install a whole ubuntu. With `vagrant ssh` you can log in into the machine. + +## Testing + +Once you have SSH'd into the machine, you'll see a plain ZSH. To test the other frameworks, you just have to switch to one of the following users: + + * `vagrant-antigen` + * `vagrant-prezto` + * `vagrant-omz` + +To switch use `sudo -i -H -u `. `-i` stands for "simulate initial login", `-H` sets the "$HOME" variable to the directory of the user , `-u` for the username. + +All users have `vagrant` as password and are in the /etc/sudoers. + +The regular `vagrant` user has a plain ZSH with the powerlevel9k theme. diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/Vagrantfile b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/Vagrantfile new file mode 100644 index 0000000..a421c70 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/Vagrantfile @@ -0,0 +1,82 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure(2) do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://atlas.hashicorp.com/search. + config.vm.box = "ubuntu/precise64" + + # Bootstrap + config.vm.provision :shell, path: "bootstrap.sh", privileged: false + config.vm.provision :shell, path: "../test-vm-providers/plain.sh", privileged: false + config.vm.provision :shell, path: "antigen.sh" + config.vm.provision :shell, path: "prezto.sh" + config.vm.provision :shell, path: "omz.sh" + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + # config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + config.vm.synced_folder "..", "/vagrant_data" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + + config.vm.provider "virtualbox" do |vb| + + # Change name to "powerlevel9k" + vb.name = "powerlevel9k" + + # Display the VirtualBox GUI when booting the machine + #vb.gui = true + + # Customize the amount of memory on the VM: + vb.memory = "256" + end + # + # View the documentation for the provider you are using for more + # information on available options. + + # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies + # such as FTP and Heroku are also available. See the documentation at + # https://docs.vagrantup.com/v2/push/atlas.html for more information. + # config.push.define "atlas" do |push| + # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" + # end + + # Enable provisioning with a shell script. Additional provisioners such as + # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the + # documentation for more information about their specific syntax and use. + # config.vm.provision "shell", inline: <<-SHELL + # sudo apt-get update + # sudo apt-get install -y apache2 + # SHELL +end diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/antigen.sh b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/antigen.sh new file mode 100644 index 0000000..2c56332 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/antigen.sh @@ -0,0 +1,30 @@ +#!/usr/bin/zsh +# We need to run this script in ZSH, so that switching user works! +NEW_USER=vagrant-antigen +# Create User +PASSWORD='$6$OgLg9v2Z$Db38Jr9inZG7y8BzL8kqFK23fF5jZ7FU1oiIBLFjNYR9XVX03fwQayMgA6Rm1rzLbXaf.gkZaTWhB9pv5XLq11' +useradd -p $PASSWORD -g vagrant -s $(which zsh) -m $NEW_USER +echo "$NEW_USER ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/$NEW_USER +chmod 440 /etc/sudoers.d/$NEW_USER + +( + # Change User (See http://unix.stackexchange.com/questions/86778/why-cant-we-execute-a-list-of-commands-as-different-user-without-sudo) + USERNAME=$NEW_USER + #UID=$(id -u $NEW_USER) + #EUID=$(id -u $NEW_USER) + HOME=/home/$NEW_USER + + echo " +source ~/antigen/antigen.zsh\n +antigen theme /vagrant_data powerlevel9k --no-local-clone\n +antigen apply +" > ~/.zshrc + + # install antigen + mkdir ~/antigen + curl -qL https://raw.githubusercontent.com/zsh-users/antigen/master/antigen.zsh > ~/antigen/antigen.zsh + source ~/antigen/antigen.zsh + + # setup environment + /vagrant_data/test-vm-providers/setup-environment.sh +) diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/bootstrap.sh b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/bootstrap.sh new file mode 100644 index 0000000..f680d4b --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/bootstrap.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +#sudo apt-get update + +sudo apt-get install -y curl +sudo apt-get install -y git + +sudo apt-get install -y zsh +sudo chsh -s $(which zsh) vagrant + +# Install mercurial +sudo apt-get install -y mercurial +# Install Subversion +sudo apt-get install -y subversion +# install golang +echo 'golang-go golang-go/dashboard boolean false' | sudo debconf-set-selections +sudo apt-get install -y golang +# Install dependencies for tests +sudo apt-get install -y jq node ruby python python-virtualenv \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/omz.sh b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/omz.sh new file mode 100644 index 0000000..73b659f --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/omz.sh @@ -0,0 +1,33 @@ +#!/usr/bin/zsh +# We need to run this script in ZSH, so that switching user works! +NEW_USER=vagrant-omz +# Create User +PASSWORD='$6$OgLg9v2Z$Db38Jr9inZG7y8BzL8kqFK23fF5jZ7FU1oiIBLFjNYR9XVX03fwQayMgA6Rm1rzLbXaf.gkZaTWhB9pv5XLq11' +useradd -p $PASSWORD -g vagrant -s $(which zsh) -m $NEW_USER +echo "$NEW_USER ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/$NEW_USER +chmod 440 /etc/sudoers.d/$NEW_USER + +( + # Change User (See http://unix.stackexchange.com/questions/86778/why-cant-we-execute-a-list-of-commands-as-different-user-without-sudo) + USERNAME=$NEW_USER + #UID=$(id -u $NEW_USER) + #EUID=$(id -u $NEW_USER) + HOME=/home/$NEW_USER + SHELL=$(which zsh) + + sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" + + mkdir -p ~/.oh-my-zsh/custom/themes + ln -s /vagrant_data ~/.oh-my-zsh/custom/themes/powerlevel9k + + echo ' +export ZSH=$HOME/.oh-my-zsh +ZSH_THEME="powerlevel9k/powerlevel9k" +plugins=(git rake ruby) + +source $ZSH/oh-my-zsh.sh +' > $HOME/.zshrc + + # setup environment + /vagrant_data/test-vm-providers/setup-environment.sh +) diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/prezto.sh b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/prezto.sh new file mode 100644 index 0000000..3ac3850 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test-vm/prezto.sh @@ -0,0 +1,29 @@ +#!/usr/bin/zsh +# We need to run this script in ZSH, so that switching user works! +NEW_USER=vagrant-prezto +# Create User +PASSWORD='$6$OgLg9v2Z$Db38Jr9inZG7y8BzL8kqFK23fF5jZ7FU1oiIBLFjNYR9XVX03fwQayMgA6Rm1rzLbXaf.gkZaTWhB9pv5XLq11' +useradd -p $PASSWORD -g vagrant -s $(which zsh) -m $NEW_USER +echo "$NEW_USER ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/$NEW_USER +chmod 440 /etc/sudoers.d/$NEW_USER + +( + # Change User (See http://unix.stackexchange.com/questions/86778/why-cant-we-execute-a-list-of-commands-as-different-user-without-sudo) + USERNAME=$NEW_USER + #UID=$(id -u $NEW_USER) + #EUID=$(id -u $NEW_USER) + HOME=/home/$NEW_USER + + git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto" + + setopt EXTENDED_GLOB + for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do + ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}" + done + + ln -s /vagrant_data/powerlevel9k.zsh-theme ~/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup + sed -i "s/theme\ 'sorin'/theme\ 'powerlevel9k'/g" ~/.zpreztorc + + # setup environment + /vagrant_data/test-vm-providers/setup-environment.sh +) diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/core/color_overriding.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/core/color_overriding.spec new file mode 100755 index 0000000..f2c3d89 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/core/color_overriding.spec @@ -0,0 +1,62 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + # Load Powerlevel9k + source powerlevel9k.zsh-theme +} + +function testDynamicColoringOfSegmentsWork() { + local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(date) + local POWERLEVEL9K_DATE_ICON="date-icon" + local POWERLEVEL9K_DATE_BACKGROUND='red' + + assertEquals "%K{001} %F{000}date-icon %f%F{000}%D{%d.%m.%y} %k%F{001}%f " "$(build_left_prompt)" +} + +function testDynamicColoringOfVisualIdentifiersWork() { + local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(date) + local POWERLEVEL9K_DATE_ICON="date-icon" + local POWERLEVEL9K_DATE_VISUAL_IDENTIFIER_COLOR='green' + + assertEquals "%K{007} %F{002}date-icon %f%F{000}%D{%d.%m.%y} %k%F{007}%f " "$(build_left_prompt)" +} + +function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() { + local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(date) + local POWERLEVEL9K_DATE_ICON="date-icon" + local POWERLEVEL9K_DATE_VISUAL_IDENTIFIER_COLOR='green' + local POWERLEVEL9K_DATE_FOREGROUND='red' + local POWERLEVEL9K_DATE_BACKGROUND='yellow' + + assertEquals "%K{003} %F{002}date-icon %f%F{001}%D{%d.%m.%y} %k%F{003}%f " "$(build_left_prompt)" +} + +function testColorOverridingOfStatefulSegment() { + local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(host) + local POWERLEVEL9K_SSH_ICON="ssh-icon" + local POWERLEVEL9K_HOST_REMOTE_BACKGROUND='red' + local POWERLEVEL9K_HOST_REMOTE_FOREGROUND='green' + # Provoke state + local SSH_CLIENT="x" + + assertEquals "%K{001} %F{002}ssh-icon %f%F{002}%m %k%F{001}%f " "$(build_left_prompt)" +} + +function testColorOverridingOfCustomSegment() { + local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + local POWERLEVEL9K_CUSTOM_WORLD_ICON='CW' + local POWERLEVEL9K_CUSTOM_WORLD_VISUAL_IDENTIFIER_COLOR='green' + local POWERLEVEL9K_CUSTOM_WORLD_FOREGROUND='red' + local POWERLEVEL9K_CUSTOM_WORLD_BACKGROUND='red' + + assertEquals "%K{001} %F{002}CW %f%F{001}world %k%F{001}%f " "$(build_left_prompt)" +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/core/joining_segments.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/core/joining_segments.spec new file mode 100755 index 0000000..18213a5 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/core/joining_segments.spec @@ -0,0 +1,187 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + # Load Powerlevel9k + source powerlevel9k.zsh-theme +} + +function testLeftNormalSegmentsShouldNotBeJoined() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3 custom_world4_joined custom_world5 custom_world6) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" + local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD6="echo world6" + + assertEquals "%K{007} %F{000}world1 %K{007}%F{000} %F{000}world2 %K{007}%F{000} %F{000}world4 %K{007}%F{000} %F{000}world6 %k%F{007}%f " "$(build_left_prompt)" +} + +function testLeftJoinedSegments() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + + assertEquals "%K{007} %F{000}world1 %K{007}%F{000}%F{000}world2 %k%F{007}%f " "$(build_left_prompt)" +} + +function testLeftTransitiveJoinedSegments() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined custom_world3_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + local POWERLEVEL9K_CUSTOM_WORLD3="echo world3" + + assertEquals "%K{007} %F{000}world1 %K{007}%F{000}%F{000}world2 %K{007}%F{000}%F{000}world3 %k%F{007}%f " "$(build_left_prompt)" +} + +function testLeftTransitiveJoiningWithConditionalJoinedSegment() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined custom_world3_joined custom_world4_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" + + assertEquals "%K{007} %F{000}world1 %K{007}%F{000}%F{000}world2 %K{007}%F{000}%F{000}world4 %k%F{007}%f " "$(build_left_prompt)" +} + +function testLeftPromotingSegmentWithConditionalPredecessor() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD3="echo world3" + + assertEquals "%K{007} %F{000}world1 %K{007}%F{000} %F{000}world3 %k%F{007}%f " "$(build_left_prompt)" +} + +function testLeftPromotingSegmentWithJoinedConditionalPredecessor() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined custom_world4_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" + + assertEquals "%K{007} %F{000}world1 %K{007}%F{000} %F{000}world4 %k%F{007}%f " "$(build_left_prompt)" +} + +function testLeftPromotingSegmentWithDeepJoinedConditionalPredecessor() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined custom_world4_joined custom_world5_joined custom_world6_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" + local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD6="echo world6" + + assertEquals "%K{007} %F{000}world1 %K{007}%F{000} %F{000}world4 %K{007}%F{000}%F{000}world6 %k%F{007}%f " "$(build_left_prompt)" +} + +function testLeftJoiningBuiltinSegmentWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(php_version php_version_joined) + alias php="echo PHP 1.2.3" + + assertEquals "%K{013} %F{255}PHP 1.2.3 %K{013}%F{255}%F{255}PHP 1.2.3 %k%F{013}%f " "$(build_left_prompt)" + + unalias php +} + +function testRightNormalSegmentsShouldNotBeJoined() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3 custom_world4 custom_world5_joined custom_world6) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" + local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD6="echo world6" + + assertEquals "%F{007}%f%K{007}%F{000} world1 %f%F{000}%f%K{007}%F{000} world2 %f%F{000}%f%K{007}%F{000} world4 %f%F{000}%f%K{007}%F{000} world6%E" "$(build_right_prompt)" +} + +function testRightJoinedSegments() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + + assertEquals "%F{007}%f%K{007}%F{000} world1 %f%K{007}%F{000}world2%E" "$(build_right_prompt)" +} + +function testRightTransitiveJoinedSegments() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined custom_world3_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + local POWERLEVEL9K_CUSTOM_WORLD3="echo world3" + + assertEquals "%F{007}%f%K{007}%F{000} world1 %f%K{007}%F{000}world2 %f%K{007}%F{000}world3%E" "$(build_right_prompt)" +} + +function testRightTransitiveJoiningWithConditionalJoinedSegment() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined custom_world3_joined custom_world4_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" + + assertEquals "%F{007}%f%K{007}%F{000} world1 %f%K{007}%F{000}world2 %f%K{007}%F{000}world4%E" "$(build_right_prompt)" +} + +function testRightPromotingSegmentWithConditionalPredecessor() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD3="echo world3" + + assertEquals "%F{007}%f%K{007}%F{000} world1 %f%F{000}%f%K{007}%F{000} world3%E" "$(build_right_prompt)" +} + +function testRightPromotingSegmentWithJoinedConditionalPredecessor() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined custom_world4_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" + + assertEquals "%F{007}%f%K{007}%F{000} world1 %f%F{000}%f%K{007}%F{000} world4%E" "$(build_right_prompt)" +} + +function testRightPromotingSegmentWithDeepJoinedConditionalPredecessor() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined custom_world4_joined custom_world5_joined custom_world6_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" + local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD6="echo world6" + + assertEquals "%F{007}%f%K{007}%F{000} world1 %f%F{000}%f%K{007}%F{000} world4 %f%K{007}%F{000}world6%E" "$(build_right_prompt)" +} + +function testRightJoiningBuiltinSegmentWorks() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(php_version php_version_joined) + alias php="echo PHP 1.2.3" + + assertEquals "%F{013}%f%K{013}%F{255} PHP 1.2.3 %f%K{013}%F{255}PHP 1.2.3%E" "$(build_right_prompt)" + + unalias php +} +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/core/prompt.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/core/prompt.spec new file mode 100755 index 0000000..47d3ac7 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/core/prompt.spec @@ -0,0 +1,104 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + # Load Powerlevel9k + source powerlevel9k.zsh-theme +} + +function testSegmentOnRightSide() { + # Reset RPROMPT, so a running P9K does not interfere with the test + local RPROMPT= + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + local POWERLEVEL9K_CUSTOM_WORLD2='echo world2' + + powerlevel9k_prepare_prompts + + local reset_attributes=$'\e[00m' + assertEquals "%f%b%k%F{007}%f%K{007}%F{000} world1 %f%F{000}%f%K{007}%F{000} world2%E%{${reset_attributes}%}" "${(e)RPROMPT}" +} + +function testDisablingRightPrompt() { + # Reset RPROMPT, so a running P9K does not interfere with the test + local RPROMPT= + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + local POWERLEVEL9K_CUSTOM_WORLD2='echo world2' + local POWERLEVEL9K_DISABLE_RPROMPT=true + + powerlevel9k_prepare_prompts + + assertEquals "" "${(e)RPROMPT}" +} + +function testLeftMultilinePrompt() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + local POWERLEVEL9K_PROMPT_ON_NEWLINE=true + + powerlevel9k_prepare_prompts + + local nl=$'\n' + assertEquals "╭─%f%b%k%K{007} %F{000}world1 %k%F{007}%f ${nl}╰─ " "${(e)PROMPT}" +} + +function testRightPromptOnSameLine() { + # Reset RPROMPT, so a running P9K does not interfere with the test + local RPROMPT= + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + + local POWERLEVEL9K_PROMPT_ON_NEWLINE=true + local POWERLEVEL9K_RPROMPT_ON_NEWLINE=false # We want the RPROMPT on the same line as our left prompt + + # Skip test, as this cannot be tested properly. + # The "go one line up" instruction does not get + # printed as real characters in RPROMPT. + # On command line the assert statement produces + # a visually identical output as we expect, but + # it fails anyway. :( + startSkipping + + powerlevel9k_prepare_prompts + assertEquals "%{\e[1A%}%F{007}%f%K{007}%F{000} world1 %f%{\e[1B%}" "${(e)RPROMPT}" +} + +function testPrefixingFirstLineOnLeftPrompt() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + + local POWERLEVEL9K_PROMPT_ON_NEWLINE=true + local POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX='XXX' + + powerlevel9k_prepare_prompts + + local nl=$'\n' + assertEquals "XXX%f%b%k%K{007} %F{000}world1 %k%F{007}%f ${nl}╰─ " "${(e)PROMPT}" +} + +function testPrefixingSecondLineOnLeftPrompt() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + + local POWERLEVEL9K_PROMPT_ON_NEWLINE=true + local POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX='XXX' + + powerlevel9k_prepare_prompts + + local nl=$'\n' + assertEquals "╭─%f%b%k%K{007} %F{000}world1 %k%F{007}%f ${nl}XXX" "${(e)PROMPT}" +} + +source shunit2/shunit2 diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/core/visual_identifier.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/core/visual_identifier.spec new file mode 100755 index 0000000..c6c6bef --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/core/visual_identifier.spec @@ -0,0 +1,60 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + source functions/* +} + +function testOverwritingIconsWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here' + + assertEquals "%K{007} %F{000}icon-here %f%F{000}world1 %k%F{007}%f " "$(build_left_prompt)" +} + +function testVisualIdentifierAppearsBeforeSegmentContentOnLeftSegments() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here' + + assertEquals "%K{007} %F{000}icon-here %f%F{000}world1 %k%F{007}%f " "$(build_left_prompt)" +} + +function testVisualIdentifierAppearsAfterSegmentContentOnRightSegments() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here' + + assertEquals "%F{007}%f%K{007}%F{000} world1%F{000} icon-here%f%E" "$(build_right_prompt)" +} + +function testVisualIdentifierPrintsNothingIfNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + + assertEquals "%K{007} %F{000}world1 %k%F{007}%f " "$(build_left_prompt)" +} + +function testVisualIdentifierIsPrintedInNumericalColorCode() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + local POWERLEVEL9K_CUSTOM_WORLD1_ICON="xxx" + local POWERLEVEL9K_CUSTOM_WORLD1_VISUAL_IDENTIFIER_COLOR="purple3" + + assertEquals "%K{007} %F{056}xxx %f%F{000}world1 %k%F{007}%f " "$(build_left_prompt)" +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/functions/colors.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/functions/colors.spec new file mode 100755 index 0000000..4ee7120 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/functions/colors.spec @@ -0,0 +1,67 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + # Load Powerlevel9k + source functions/colors.zsh +} + +function testGetColorCodeWithAnsiForegroundColor() { + assertEquals '002' "$(getColorCode 'green')" +} + +function testGetColorCodeWithAnsiBackgroundColor() { + assertEquals '002' "$(getColorCode 'bg-green')" +} + +function testGetColorCodeWithNumericalColor() { + assertEquals '002' "$(getColorCode '002')" +} + +function testGetColorCodeWithNoneColor() { + assertEquals 'none' "$(getColorCode 'NONE')" +} + +function testIsSameColorComparesAnsiForegroundAndNumericalColorCorrectly() { + assertTrue "isSameColor 'green' '002'" +} + +function testIsSameColorComparesAnsiBackgroundAndNumericalColorCorrectly() { + assertTrue "isSameColor 'bg-green' '002'" +} + +function testIsSameColorComparesShortCodesCorrectly() { + assertTrue "isSameColor '002' '2'" +} + +function testIsSameColorDoesNotYieldNotEqualColorsTruthy() { + assertFalse "isSameColor 'green' '003'" +} + +function testIsSameColorHandlesNoneCorrectly() { + assertTrue "isSameColor 'none' 'NOnE'" +} + +function testIsSameColorCompareTwoNoneColorsCorrectly() { + assertTrue "isSameColor 'none' 'none'" +} + +function testIsSameColorComparesColorWithNoneCorrectly() { + assertFalse "isSameColor 'green' 'none'" +} + +function testBrightColorsWork() { + # We had some code in the past that equalized bright colors + # with normal ones. This code is now gone, and this test should + # ensure that all input channels for bright colors are handled + # correctly. + assertTrue "isSameColor 'cyan' '006'" + assertEquals '006' "$(getColorCode 'cyan')" + assertEquals '006' "$(getColor 'cyan')" +} + +source shunit2/shunit2 diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/functions/icons.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/functions/icons.spec new file mode 100755 index 0000000..ec0cb1f --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/functions/icons.spec @@ -0,0 +1,473 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + # Store old value for LC_CTYPE + _OLD_LC_CTYPE="${LC_CTYPE}" + # Reset actual LC_CTYPE + unset LC_CTYPE +} + +function tearDown() { + # Restore LC_CTYPE + LC_CTYPE="${_OLD_LC_CTYPE}" +} + +function testLcCtypeIsSetCorrectlyInDefaultMode() { + local POWERLEVEL9K_MODE="default" + # Load Powerlevel9k + source functions/icons.zsh + + assertEquals 'en_US.UTF-8' "${LC_CTYPE}" +} + +function testLcCtypeIsSetCorrectlyInAwesomePatchedMode() { + local POWERLEVEL9K_MODE="awesome-patched" + # Load Powerlevel9k + source functions/icons.zsh + + assertEquals 'en_US.UTF-8' "${LC_CTYPE}" +} + +function testLcCtypeIsSetCorrectlyInAwesomeFontconfigMode() { + local POWERLEVEL9K_MODE="awesome-fontconfig" + # Load Powerlevel9k + source functions/icons.zsh + + assertEquals 'en_US.UTF-8' "${LC_CTYPE}" +} + +function testLcCtypeIsSetCorrectlyInNerdfontFontconfigMode() { + local POWERLEVEL9K_MODE="nerdfont-fontconfig" + # Load Powerlevel9k + source functions/icons.zsh + + assertEquals 'en_US.UTF-8' "${LC_CTYPE}" +} + +function testLcCtypeIsSetCorrectlyInFlatMode() { + local POWERLEVEL9K_MODE="flat" + # Load Powerlevel9k + source functions/icons.zsh + + assertEquals 'en_US.UTF-8' "${LC_CTYPE}" +} + +function testLcCtypeIsSetCorrectlyInCompatibleMode() { + local POWERLEVEL9K_MODE="compatible" + # Load Powerlevel9k + source functions/icons.zsh + + assertEquals 'en_US.UTF-8' "${LC_CTYPE}" +} + +# Go through all icons defined in default mode, and +# check if all of them are defined in the other modes. +function testAllIconsAreDefinedLikeInDefaultMode() { + # Always compare against this mode + local _P9K_TEST_MODE="default" + local POWERLEVEL9K_MODE="${_P9K_TEST_MODE}" + source functions/icons.zsh + # _ICONS_UNDER_TEST is an array of just the keys of $icons. + # We later check via (r) "subscript" flag that our key + # is in the values of our flat array. + typeset -ah _ICONS_UNDER_TEST + _ICONS_UNDER_TEST=(${(k)icons[@]}) + + # Switch to "awesome-patched" mode + POWERLEVEL9K_MODE="awesome-patched" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + # Iterate over all keys found in the _ICONS_UNDER_TEST + # array and compare it with the icons array of the + # current POWERLEVEL9K_MODE. + # Use parameter expansion, to directly check if the + # key exists in the flat current array of keys. That + # is quite complicated, but there seems no easy way + # to check the mere existance of a key in an array. + # The usual way would always return the value, so that + # would do the wrong thing as we have some (on purpose) + # empty values. + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "awesome-fontconfig" mode + POWERLEVEL9K_MODE="awesome-fontconfig" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "nerdfont-fontconfig" mode + POWERLEVEL9K_MODE="nerdfont-fontconfig" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "nerdfont-complete" mode + POWERLEVEL9K_MODE="nerdfont-complete" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "flat" mode + POWERLEVEL9K_MODE="flat" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "compatible" mode + POWERLEVEL9K_MODE="compatible" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + unset current_icons + unset _ICONS_UNDER_TEST +} + +# Go through all icons defined in awesome-patched mode, and +# check if all of them are defined in the other modes. +function testAllIconsAreDefinedLikeInAwesomePatchedMode() { + # Always compare against this mode + local _P9K_TEST_MODE="awesome-patched" + local POWERLEVEL9K_MODE="$_P9K_TEST_MODE" + source functions/icons.zsh + # _ICONS_UNDER_TEST is an array of just the keys of $icons. + # We later check via (r) "subscript" flag that our key + # is in the values of our flat array. + typeset -ah _ICONS_UNDER_TEST + _ICONS_UNDER_TEST=(${(k)icons[@]}) + + # Switch to "default" mode + POWERLEVEL9K_MODE="default" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + # Iterate over all keys found in the _ICONS_UNDER_TEST + # array and compare it with the icons array of the + # current POWERLEVEL9K_MODE. + # Use parameter expansion, to directly check if the + # key exists in the flat current array of keys. That + # is quite complicated, but there seems no easy way + # to check the mere existance of a key in an array. + # The usual way would always return the value, so that + # would do the wrong thing as we have some (on purpose) + # empty values. + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "awesome-fontconfig" mode + POWERLEVEL9K_MODE="awesome-fontconfig" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "nerdfont-fontconfig" mode + POWERLEVEL9K_MODE="nerdfont-fontconfig" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "nerdfont-complete" mode + POWERLEVEL9K_MODE="nerdfont-complete" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "flat" mode + POWERLEVEL9K_MODE="flat" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "compatible" mode + POWERLEVEL9K_MODE="compatible" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + unset current_icons + unset _ICONS_UNDER_TEST +} + +# Go through all icons defined in awesome-fontconfig mode, and +# check if all of them are defined in the other modes. +function testAllIconsAreDefinedLikeInAwesomeFontconfigMode() { + # Always compare against this mode + local _P9K_TEST_MODE="awesome-fontconfig" + local POWERLEVEL9K_MODE="$_P9K_TEST_MODE" + source functions/icons.zsh + # _ICONS_UNDER_TEST is an array of just the keys of $icons. + # We later check via (r) "subscript" flag that our key + # is in the values of our flat array. + typeset -ah _ICONS_UNDER_TEST + _ICONS_UNDER_TEST=(${(k)icons[@]}) + + # Switch to "default" mode + POWERLEVEL9K_MODE="default" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + # Iterate over all keys found in the _ICONS_UNDER_TEST + # array and compare it with the icons array of the + # current POWERLEVEL9K_MODE. + # Use parameter expansion, to directly check if the + # key exists in the flat current array of keys. That + # is quite complicated, but there seems no easy way + # to check the mere existance of a key in an array. + # The usual way would always return the value, so that + # would do the wrong thing as we have some (on purpose) + # empty values. + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "awesome-patched" mode + POWERLEVEL9K_MODE="awesome-patched" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "nerdfont-fontconfig" mode + POWERLEVEL9K_MODE="nerdfont-fontconfig" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "nerdfont-complete" mode + POWERLEVEL9K_MODE="nerdfont-complete" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "flat" mode + POWERLEVEL9K_MODE="flat" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "compatible" mode + POWERLEVEL9K_MODE="compatible" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + unset current_icons + unset _ICONS_UNDER_TEST +} + +# Go through all icons defined in nerdfont-fontconfig mode, and +# check if all of them are defined in the other modes. +function testAllIconsAreDefinedLikeInNerdfontFontconfigMode() { + # Always compare against this mode + local _P9K_TEST_MODE="nerdfont-fontconfig" + local POWERLEVEL9K_MODE="$_P9K_TEST_MODE" + source functions/icons.zsh + # _ICONS_UNDER_TEST is an array of just the keys of $icons. + # We later check via (r) "subscript" flag that our key + # is in the values of our flat array. + typeset -ah _ICONS_UNDER_TEST + _ICONS_UNDER_TEST=(${(k)icons[@]}) + + # Switch to "default" mode + POWERLEVEL9K_MODE="default" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + # Iterate over all keys found in the _ICONS_UNDER_TEST + # array and compare it with the icons array of the + # current POWERLEVEL9K_MODE. + # Use parameter expansion, to directly check if the + # key exists in the flat current array of keys. That + # is quite complicated, but there seems no easy way + # to check the mere existance of a key in an array. + # The usual way would always return the value, so that + # would do the wrong thing as we have some (on purpose) + # empty values. + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "awesome-patched" mode + POWERLEVEL9K_MODE="awesome-patched" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "awesome-fontconfig" mode + POWERLEVEL9K_MODE="awesome-fontconfig" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "nerdfont-complete" mode + POWERLEVEL9K_MODE="nerdfont-complete" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "flat" mode + POWERLEVEL9K_MODE="flat" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "compatible" mode + POWERLEVEL9K_MODE="compatible" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + unset current_icons + unset _ICONS_UNDER_TEST +} + +# Go through all icons defined in nerdfont-complete mode, and +# check if all of them are defined in the other modes. +function testAllIconsAreDefinedLikeInNerdfontCompleteMode() { + # Always compare against this mode + local _P9K_TEST_MODE="nerdfont-complete" + local POWERLEVEL9K_MODE="$_P9K_TEST_MODE" + source functions/icons.zsh + # _ICONS_UNDER_TEST is an array of just the keys of $icons. + # We later check via (r) "subscript" flag that our key + # is in the values of our flat array. + typeset -ah _ICONS_UNDER_TEST + _ICONS_UNDER_TEST=(${(k)icons[@]}) + + # Switch to "default" mode + POWERLEVEL9K_MODE="default" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + # Iterate over all keys found in the _ICONS_UNDER_TEST + # array and compare it with the icons array of the + # current POWERLEVEL9K_MODE. + # Use parameter expansion, to directly check if the + # key exists in the flat current array of keys. That + # is quite complicated, but there seems no easy way + # to check the mere existance of a key in an array. + # The usual way would always return the value, so that + # would do the wrong thing as we have some (on purpose) + # empty values. + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "awesome-patched" mode + POWERLEVEL9K_MODE="awesome-patched" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "awesome-fontconfig" mode + POWERLEVEL9K_MODE="awesome-fontconfig" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "nerdfont-fontconfig" mode + POWERLEVEL9K_MODE="nerdfont-fontconfig" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "flat" mode + POWERLEVEL9K_MODE="flat" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "compatible" mode + POWERLEVEL9K_MODE="compatible" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + unset current_icons + unset _ICONS_UNDER_TEST +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/functions/utilities.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/functions/utilities.spec new file mode 100755 index 0000000..b727c1f --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/functions/utilities.spec @@ -0,0 +1,109 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + # Load Powerlevel9k + source functions/icons.zsh + source functions/utilities.zsh +} + +function testDefinedFindsDefinedVariable() { + my_var='X' + + assertTrue "defined 'my_var'" + unset my_var +} + +function testDefinedDoesNotFindUndefinedVariable() { + assertFalse "defined 'my_var'" +} + +function testSetDefaultSetsVariable() { + set_default 'my_var' 'x' + + assertEquals 'x' "$my_var" + unset my_var +} + +function testPrintSizeHumanReadableWithBigNumber() { + # Interesting: Currently we can't support numbers bigger than that. + assertEquals '0.87E' "$(printSizeHumanReadable 1000000000000000000)" +} + +function testPrintSizeHumanReadableWithExabytesAsBase() { + assertEquals '9.77Z' "$(printSizeHumanReadable 10000 'E')" +} + +function testGetRelevantItem() { + typeset -a list + list=(a b c) + local callback='[[ "$item" == "b" ]] && echo "found"' + + local result=$(getRelevantItem "$list" "$callback") + assertEquals 'found' "$result" + + unset list +} + +function testGetRelevantItemDoesNotReturnNotFoundItems() { + typeset -a list + list=(a b c) + local callback='[[ "$item" == "d" ]] && echo "found"' + + local result=$(getRelevantItem "$list" "$callback") + assertEquals '' '' + + unset list +} + +function testSegmentShouldBeJoinedIfDirectPredecessingSegmentIsJoined() { + typeset -a segments + segments=(a b_joined c_joined) + # Look at the third segment + local current_index=3 + local last_element_index=2 + + local joined + segmentShouldBeJoined $current_index $last_element_index "$segments" && joined=true || joined=false + assertTrue "$joined" + + unset segments +} + +function testSegmentShouldBeJoinedIfPredecessingSegmentIsJoinedTransitivley() { + typeset -a segments + segments=(a b_joined c_joined) + # Look at the third segment + local current_index=3 + # The last printed segment was the first one, + # the second segmend was conditional. + local last_element_index=1 + + local joined + segmentShouldBeJoined $current_index $last_element_index "$segments" && joined=true || joined=false + assertTrue "$joined" + + unset segments +} + +function testSegmentShouldNotBeJoinedIfPredecessingSegmentIsNotJoinedButConditional() { + typeset -a segments + segments=(a b_joined c d_joined) + # Look at the fourth segment + local current_index=4 + # The last printed segment was the first one, + # the second segmend was conditional. + local last_element_index=1 + + local joined + segmentShouldBeJoined $current_index $last_element_index "$segments" && joined=true || joined=false + assertFalse "$joined" + + unset segments +} + +source shunit2/shunit2 diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/powerlevel9k.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/powerlevel9k.spec new file mode 100755 index 0000000..586c2b2 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/powerlevel9k.spec @@ -0,0 +1,123 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + source functions/* + + # Unset mode, so that user settings + # do not interfere with tests + unset POWERLEVEL9K_MODE +} + +function testJoinedSegments() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir dir_joined) + cd /tmp + + assertEquals "%K{004} %F{000}/tmp %K{004}%F{000}%F{000}/tmp %k%F{004}%f " "$(build_left_prompt)" + + cd - +} + +function testTransitiveJoinedSegments() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir root_indicator_joined dir_joined) + cd /tmp + + assertEquals "%K{004} %F{000}/tmp %K{004}%F{000}%F{000}/tmp %k%F{004}%f " "$(build_left_prompt)" + + cd - +} + +function testJoiningWithConditionalSegment() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir background_jobs dir_joined) + cd /tmp + + assertEquals "%K{004} %F{000}/tmp %K{004}%F{000} %F{000}/tmp %k%F{004}%f " "$(build_left_prompt)" + + cd - +} + +function testDynamicColoringOfSegmentsWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='red' + cd /tmp + + assertEquals "%K{001} %F{000}/tmp %k%F{001}%f " "$(build_left_prompt)" + + cd - +} + +function testDynamicColoringOfVisualIdentifiersWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR='green' + local POWERLEVEL9K_FOLDER_ICON="icon-here" + + cd /tmp + + assertEquals "%K{004} %F{002}icon-here %f%F{000}/tmp %k%F{004}%f " "$(build_left_prompt)" + + cd - +} + +function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR='green' + local POWERLEVEL9K_DIR_DEFAULT_FOREGROUND='red' + local POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='yellow' + local POWERLEVEL9K_FOLDER_ICON="icon-here" + + # Re-Source the icons, as the POWERLEVEL9K_MODE is directly + # evaluated there. + source functions/icons.zsh + + cd /tmp + + assertEquals "%K{003} %F{002}icon-here %f%F{001}/tmp %k%F{003}%f " "$(build_left_prompt)" + + cd - +} + +function testOverwritingIconsWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_FOLDER_ICON='icon-here' + #local testFolder=$(mktemp -d -p p9k) + # Move testFolder under home folder + #mv testFolder ~ + # Go into testFolder + #cd ~/$testFolder + + cd /tmp + assertEquals "%K{004} %F{000}icon-here %f%F{000}/tmp %k%F{004}%f " "$(build_left_prompt)" + + cd - + # rm -fr ~/$testFolder +} + +function testNewlineOnRpromptCanBeDisabled() { + local POWERLEVEL9K_PROMPT_ON_NEWLINE=true + local POWERLEVEL9K_RPROMPT_ON_NEWLINE=false + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + local POWERLEVEL9K_CUSTOM_RWORLD='echo rworld' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_rworld) + + powerlevel9k_prepare_prompts + assertEquals '$(print_icon MULTILINE_FIRST_PROMPT_PREFIX) world  $(print_icon MULTILINE_LAST_PROMPT_PREFIX) rworld' "$(print -P ${PROMPT}${RPROMPT})" +} + +source shunit2/shunit2 diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/anaconda.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/anaconda.spec new file mode 100755 index 0000000..efcfc03 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/anaconda.spec @@ -0,0 +1,69 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" +} + +function testAnacondaSegmentPrintsNothingIfNoAnacondaPathIsSet() { + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda custom_world) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + # Unset anacona variables + unset CONDA_ENV_PATH + unset CONDA_PREFIX + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +function testAnacondaSegmentWorksIfOnlyAnacondaPathIsSet() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda) + local POWERLEVEL9K_PYTHON_ICON="icon-here" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + CONDA_ENV_PATH=/tmp + unset CONDA_PREFIX + + assertEquals "%K{004} %F{000}icon-here %f%F{000}(tmp) %k%F{004}%f " "$(build_left_prompt)" +} + +function testAnacondaSegmentWorksIfOnlyAnacondaPrefixIsSet() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda) + local POWERLEVEL9K_PYTHON_ICON="icon-here" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + unset CONDA_ENV_PATH + local CONDA_PREFIX="test" + + assertEquals "%K{004} %F{000}icon-here %f%F{000}(test) %k%F{004}%f " "$(build_left_prompt)" +} + +function testAnacondaSegmentWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda) + local POWERLEVEL9K_PYTHON_ICON="icon-here" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + local CONDA_ENV_PATH=/tmp + local CONDA_PREFIX="test" + + assertEquals "%K{004} %F{000}icon-here %f%F{000}(tmptest) %k%F{004}%f " "$(build_left_prompt)" +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/aws_eb_env.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/aws_eb_env.spec new file mode 100755 index 0000000..99b418e --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/aws_eb_env.spec @@ -0,0 +1,61 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" +} + +function testAwsEbEnvSegmentPrintsNothingIfNoElasticBeanstalkEnvironmentIsSet() { + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(aws_eb_env custom_world) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +function testAwsEbEnvSegmentWorksIfElasticBeanstalkEnvironmentIsSet() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(aws_eb_env) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + mkdir -p /tmp/powerlevel9k-test/.elasticbeanstalk + echo "test:\n environment: test" > /tmp/powerlevel9k-test/.elasticbeanstalk/config.yml + cd /tmp/powerlevel9k-test + + assertEquals "%K{000} %F{002}🌱 %f%F{002}test %k%F{000}%f " "$(build_left_prompt)" + + rm -fr /tmp/powerlevel9k-test + cd - +} + +function testAwsEbEnvSegmentWorksIfElasticBeanstalkEnvironmentIsSetInParentDirectory() { + # Skip test, because currently we cannot detect + # if the configuration is in a parent directory + startSkipping # Skip test + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(aws_eb_env) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + mkdir -p /tmp/powerlevel9k-test/.elasticbeanstalk + mkdir -p /tmp/powerlevel9k-test/1/12/123/1234/12345 + echo "test:\n environment: test" > /tmp/powerlevel9k-test/.elasticbeanstalk/config.yml + cd /tmp/powerlevel9k-test/1/12/123/1234/12345 + + assertEquals "%K{000} %F{002}🌱 %f%F{002}test %k%F{000}%f " "$(build_left_prompt)" + + rm -fr /tmp/powerlevel9k-test + cd - +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/background_jobs.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/background_jobs.spec new file mode 100755 index 0000000..3d83e17 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/background_jobs.spec @@ -0,0 +1,78 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" +} + +function testBackgroundJobsSegmentPrintsNothingWithoutBackgroundJobs() { + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs custom_world) + alias jobs="nojobs 2>/dev/null" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unalias jobs +} + +function testBackgroundJobsSegmentWorksWithOneBackgroundJob() { + unset POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs) + jobs() { + echo '[1] + 30444 suspended nvim xx' + } + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{006}⚙%f %k%F{000}%f " "$(build_left_prompt)" + + unfunction jobs +} + +function testBackgroundJobsSegmentWorksWithMultipleBackgroundJobs() { + local POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE=false + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs) + jobs() { + echo "[1] 31190 suspended nvim xx" + echo "[2] - 31194 suspended nvim xx2" + echo "[3] + 31206 suspended nvim xx3" + } + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{006}⚙%f %k%F{000}%f " "$(build_left_prompt)" + + unfunction jobs +} + +function testBackgroundJobsSegmentWithVerboseMode() { + local POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE=true + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs) + jobs() { + echo "[1] 31190 suspended nvim xx" + echo "[2] - 31194 suspended nvim xx2" + echo "[3] + 31206 suspended nvim xx3" + } + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{006}⚙ %f%F{006}3 %k%F{000}%f " "$(build_left_prompt)" + + unfunction jobs +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/battery.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/battery.spec new file mode 100755 index 0000000..79e25d6 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/battery.spec @@ -0,0 +1,177 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + P9K_HOME=$(pwd) + ### Test specific + # Create default folder + FOLDER=/tmp/powerlevel9k-test + mkdir -p "${FOLDER}" + cd $FOLDER + + # Prepare folder for pmset (OSX) + PMSET_PATH=$FOLDER/usr/bin + mkdir -p $PMSET_PATH + # Prepare folder for $BATTERY (Linux) + BATTERY_PATH=$FOLDER/sys/class/power_supply + mkdir -p $BATTERY_PATH + mkdir -p $BATTERY_PATH/BAT0 + mkdir -p $BATTERY_PATH/BAT1 +} + +function tearDown() { + # Go back to powerlevel9k folder + cd "${P9K_HOME}" + # Remove eventually created test-specific folder + rm -fr "${FOLDER}" &>/dev/null + # At least remove test folder completely + rm -fr /tmp/powerlevel9k-test &>/dev/null + unset PMSET_PATH + unset BATTERY_PATH + unset FOLDER + unset P9K_HOME +} + +# Mock Battery +# For mocking pmset on OSX this function takes one argument (the +# content that pmset should echo). +# For mocking the battery on Linux this function takes two +# arguments: $1 is the capacity; $2 the battery status. +function makeBatterySay() { + if [[ -z "${FOLDER}" ]]; then + echo "Fake root path is not correctly set!" + exit 1 + fi + # OSX + echo "#!/bin/sh" > $PMSET_PATH/pmset + echo "echo \"$1\"" >> $PMSET_PATH/pmset + chmod +x $PMSET_PATH/pmset + + # Linux + local capacity="$1" + echo "$capacity" > $BATTERY_PATH/BAT0/capacity + echo "$capacity" > $BATTERY_PATH/BAT1/capacity + local battery_status="$2" + echo "$battery_status" > $BATTERY_PATH/BAT0/status + echo "$battery_status" > $BATTERY_PATH/BAT1/status +} + +function testBatterySegmentIfBatteryIsLowWhileDischargingOnOSX() { + local OS='OSX' # Fake OSX + makeBatterySay "Now drawing from 'Battery Power' + -InternalBattery-0 (id=1234567) 4%; discharging; 0:05 remaining present: true" + + assertEquals "%K{000} %F{001}🔋 %f%F{001}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})" +} + +function testBatterySegmentIfBatteryIsLowWhileChargingOnOSX() { + local OS='OSX' # Fake OSX + makeBatterySay "Now drawing from 'Battery Power' + -InternalBattery-0 (id=1234567) 4%; charging; 0:05 remaining present: true" + + assertEquals "%K{000} %F{003}🔋 %f%F{003}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})" +} + +function testBatterySegmentIfBatteryIsAlmostFullWhileDischargingOnOSX() { + local OS='OSX' # Fake OSX + makeBatterySay "Now drawing from 'Battery Power' + -InternalBattery-0 (id=1234567) 98%; discharging; 3:57 remaining present: true" + + assertEquals "%K{000} %F{007}🔋 %f%F{007}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})" +} + +function testBatterySegmentIfBatteryIsAlmostFullWhileChargingOnOSX() { + local OS='OSX' # Fake OSX + makeBatterySay "Now drawing from 'Battery Power' + -InternalBattery-0 (id=1234567) 98%; charging; 3:57 remaining present: true" + + assertEquals "%K{000} %F{003}🔋 %f%F{003}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})" +} + +function testBatterySegmentIfBatteryIsFullOnOSX() { + local OS='OSX' # Fake OSX + makeBatterySay "Now drawing from 'AC Power' + -InternalBattery-0 (id=1234567) 99%; charged; 0:00 remaining present: true" + + assertEquals "%K{000} %F{002}🔋 %f%F{002}99%% " "$(prompt_battery left 1 false ${FOLDER})" +} + +function testBatterySegmentIfBatteryIsCalculatingOnOSX() { + local OS='OSX' # Fake OSX + makeBatterySay "Now drawing from 'Battery Power' + -InternalBattery-0 (id=1234567) 99%; discharging; (no estimate) present: true" + + assertEquals "%K{000} %F{007}🔋 %f%F{007}99%% (...) " "$(prompt_battery left 1 false ${FOLDER})" +} + +function testBatterySegmentIfBatteryIsLowWhileDischargingOnLinux() { + local OS='Linux' # Fake Linux + makeBatterySay "4" "Discharging" + + assertEquals "%K{000} %F{001}🔋 %f%F{001}4%% " "$(prompt_battery left 1 false ${FOLDER})" +} + +function testBatterySegmentIfBatteryIsLowWhileChargingOnLinux() { + local OS='Linux' # Fake Linux + makeBatterySay "4" "Charging" + + assertEquals "%K{000} %F{003}🔋 %f%F{003}4%% " "$(prompt_battery left 1 false ${FOLDER})" +} + +function testBatterySegmentIfBatteryIsNormalWhileDischargingOnLinux() { + local OS='Linux' # Fake Linux + makeBatterySay "10" "Discharging" + + assertEquals "%K{000} %F{007}🔋 %f%F{007}10%% " "$(prompt_battery left 1 false ${FOLDER})" +} + +function testBatterySegmentIfBatteryIsNormalWhileChargingOnLinux() { + local OS='Linux' # Fake Linux + makeBatterySay "10" "Charging" + + assertEquals "%K{000} %F{003}🔋 %f%F{003}10%% " "$(prompt_battery left 1 false ${FOLDER})" +} + +function testBatterySegmentIfBatteryIsFullOnLinux() { + local OS='Linux' # Fake Linux + makeBatterySay "100" "Full" + + assertEquals "%K{000} %F{002}🔋 %f%F{002}100%% " "$(prompt_battery left 1 false ${FOLDER})" +} + +function testBatterySegmentIfBatteryIsNormalWithAcpiEnabledOnLinux() { + local OS='Linux' # Fake Linux + makeBatterySay "50" "Discharging" + echo "echo 'Batter 0: Discharging, 50%, 01:38:54 remaining'" > ${FOLDER}/usr/bin/acpi + chmod +x ${FOLDER}/usr/bin/acpi + # For running on Mac, we need to mock date :( + [[ -f /usr/local/bin/gdate ]] && alias date=gdate + + assertEquals "%K{000} %F{007}🔋 %f%F{007}50%% (1:38) " "$(prompt_battery left 1 false ${FOLDER})" + + unalias date &>/dev/null + # unaliasing date fails where it was never aliased (e.g. on Linux). + # This causes the whole test to fail, because the return code is + # non-zero. + return 0 +} + +function testBatterySegmentIfBatteryIsCalculatingWithAcpiEnabledOnLinux() { + local OS='Linux' # Fake Linux + makeBatterySay "50" "Discharging" + # Todo: Include real acpi output! + echo "echo 'Batter 0: Discharging, 50%, rate remaining'" > ${FOLDER}/usr/bin/acpi + chmod +x ${FOLDER}/usr/bin/acpi + + assertEquals "%K{000} %F{007}🔋 %f%F{007}50%% (...) " "$(prompt_battery left 1 false ${FOLDER})" +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/command_execution_time.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/command_execution_time.spec new file mode 100755 index 0000000..b7c3fae --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/command_execution_time.spec @@ -0,0 +1,104 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" +} + +function testCommandExecutionTimeIsNotShownIfTimeIsBelowThreshold() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world command_execution_time) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + # Override payload + local _P9K_COMMAND_DURATION=2 + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +function testCommandExecutionTimeThresholdCouldBeChanged() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) + local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1 + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + # Override payload + local _P9K_COMMAND_DURATION=2.03 + + assertEquals "%K{001} %F{226}Dur %f%F{226}2.03 %k%F{001}%f " "$(build_left_prompt)" +} + +function testCommandExecutionTimeThresholdCouldBeSetToZero() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) + local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0 + local _P9K_COMMAND_DURATION=0.03 + + assertEquals "%K{001} %F{226}Dur %f%F{226}0.03 %k%F{001}%f " "$(build_left_prompt)" +} + +function testCommandExecutionTimePrecisionCouldBeChanged() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) + local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0 + local POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=4 + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + # Override payload + local _P9K_COMMAND_DURATION=0.0001 + + assertEquals "%K{001} %F{226}Dur %f%F{226}0.0001 %k%F{001}%f " "$(build_left_prompt)" +} + +function testCommandExecutionTimePrecisionCouldBeSetToZero() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) + local POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0 + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + # Override payload + local _P9K_COMMAND_DURATION=23.5001 + + assertEquals "%K{001} %F{226}Dur %f%F{226}23 %k%F{001}%f " "$(build_left_prompt)" +} + +function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + # Override payload + local _P9K_COMMAND_DURATION=180 + + assertEquals "%K{001} %F{226}Dur %f%F{226}03:00 %k%F{001}%f " "$(build_left_prompt)" +} + +function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + # Override payload + local _P9K_COMMAND_DURATION=7200 + + assertEquals "%K{001} %F{226}Dur %f%F{226}02:00:00 %k%F{001}%f " "$(build_left_prompt)" +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/context.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/context.spec new file mode 100755 index 0000000..25c355a --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/context.spec @@ -0,0 +1,131 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + # Test specific settings + OLD_DEFAULT_USER=$DEFAULT_USER + unset DEFAULT_USER + + # Fix leaked state for travis + OLD_POWERLEVEL9K_CONTEXT_ALWAYS_SHOW=$POWERLEVEL9K_CONTEXT_ALWAYS_SHOW + unset POWERLEVEL9K_CONTEXT_ALWAYS_SHOW + OLD_SSH_CLIENT=$SSH_CLIENT + unset SSH_CLIENT + OLD_SSH_TTY=$SSH_TTY + unset SSH_TTY +} + +function tearDown() { + # Restore old variables + [[ -n "$OLD_DEFAULT_USER" ]] && DEFAULT_USER=$OLD_DEFAULT_USER + unset OLD_DEFAULT_USER + + [[ -n "$OLD_POWERLEVEL9K_CONTEXT_ALWAYS_SHOW" ]] && POWERLEVEL9K_CONTEXT_ALWAYS_SHOW=$OLD_POWERLEVEL9K_CONTEXT_ALWAYS_SHOW + unset OLD_POWERLEVEL9K_CONTEXT_ALWAYS_SHOW + + [[ -n "$OLD_SSH_CLIENT" ]] && SSH_CLIENT=$OLD_SSH_CLIENT + unset OLD_SSH_CLIENT + + [[ -n "$OLD_SSH_TTY" ]] && SSH_TTY=$OLD_SSH_TTY + unset OLD_SSH_TTY + + return 0 +} + +function testContextSegmentDoesNotGetRenderedWithDefaultUser() { + local DEFAULT_USER=$(whoami) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context custom_world) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +function testContextSegmentDoesGetRenderedWhenSshConnectionIsOpen() { + function sudo() { + return 0 + } + local SSH_CLIENT="putty" + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{003}%n@%m %k%F{000}%f " "$(build_left_prompt)" + + unfunction sudo +} + +function testContextSegmentWithForeignUser() { + function sudo() { + return 0 + } + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{003}%n@%m %k%F{000}%f " "$(build_left_prompt)" + + unfunction sudo +} + +# TODO: How to test root? +function testContextSegmentWithRootUser() { + startSkipping # Skip test + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{003}%n@%m %k%F{000}%f " "$(build_left_prompt)" +} + +function testOverridingContextTemplate() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) + local POWERLEVEL9K_CONTEXT_TEMPLATE=xx + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{003}xx %k%F{000}%f " "$(build_left_prompt)" +} + +function testContextSegmentIsShownIfDefaultUserIsSetWhenForced() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) + local POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true + local DEFAULT_USER=$(whoami) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{003}%n@%m %k%F{000}%f " "$(build_left_prompt)" +} + +function testContextSegmentIsShownIfForced() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) + local POWERLEVEL9K_ALWAYS_SHOW_USER=true + local DEFAULT_USER=$(whoami) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{003}$(whoami) %k%F{000}%f " "$(build_left_prompt)" +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/custom.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/custom.spec new file mode 100755 index 0000000..0f66c82 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/custom.spec @@ -0,0 +1,86 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" +} + +function testCustomDirectOutputSegment() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) + local POWERLEVEL9K_CUSTOM_WORLD="echo world" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +function testCustomClosureSegment() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) + function p9k_hello_world() { + echo "world" + } + local POWERLEVEL9K_CUSTOM_WORLD='p9k_hello_world' + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +function testSettingBackgroundForCustomSegment() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) + local POWERLEVEL9K_CUSTOM_WORLD="echo world" + local POWERLEVEL9K_CUSTOM_WORLD_BACKGROUND="yellow" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{003} %F{000}world %k%F{003}%f " "$(build_left_prompt)" +} + +function testSettingForegroundForCustomSegment() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) + local POWERLEVEL9K_CUSTOM_WORLD="echo world" + local POWERLEVEL9K_CUSTOM_WORLD_FOREGROUND="red" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{001}world %k%F{007}%f " "$(build_left_prompt)" +} + +function testSettingVisualIdentifierForCustomSegment() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) + local POWERLEVEL9K_CUSTOM_WORLD="echo world" + local POWERLEVEL9K_CUSTOM_WORLD_ICON="hw" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}hw %f%F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +function testSettingVisualIdentifierForegroundColorForCustomSegment() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) + local POWERLEVEL9K_CUSTOM_WORLD="echo world" + local POWERLEVEL9K_CUSTOM_WORLD_ICON="hw" + local POWERLEVEL9K_CUSTOM_WORLD_VISUAL_IDENTIFIER_COLOR="red" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{001}hw %f%F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/detect_virt.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/detect_virt.spec new file mode 100755 index 0000000..910f52e --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/detect_virt.spec @@ -0,0 +1,83 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + # Load Powerlevel9k + source powerlevel9k.zsh-theme +} + +function testDetectVirtSegmentPrintsNothingIfSystemdIsNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + alias systemd-detect-virt="novirt" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unalias systemd-detect-virt +} + +function testDetectVirtSegmentIfSystemdReturnsPlainName() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt) + alias systemd-detect-virt="echo 'xxx'" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{003}xxx %k%F{000}%f " "$(build_left_prompt)" + + unalias systemd-detect-virt +} + +function testDetectVirtSegmentIfRootFsIsOnExpectedInode() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt) + # Well. This is a weak test, as it fixates the implementation, + # but it is necessary, as the implementation relys on the root + # directory having the inode number "2".. + alias systemd-detect-virt="echo 'none'" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + # The original command in the implementation is "ls -di / | grep -o 2", + # which translates to: Show the inode number of "/" and test if it is "2". + alias ls="echo '2'" + + assertEquals "%K{000} %F{003}none %k%F{000}%f " "$(build_left_prompt)" + + unalias ls + unalias systemd-detect-virt +} + +function testDetectVirtSegmentIfRootFsIsNotOnExpectedInode() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt) + # Well. This is a weak test, as it fixates the implementation, + # but it is necessary, as the implementation relys on the root + # directory having the inode number "2".. + alias systemd-detect-virt="echo 'none'" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + # The original command in the implementation is "ls -di / | grep -o 2", + # which translates to: Show the inode number of "/" and test if it is "2". + alias ls="echo '3'" + + assertEquals "%K{000} %F{003}chroot %k%F{000}%f " "$(build_left_prompt)" + + unalias ls + unalias systemd-detect-virt +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/dir.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/dir.spec new file mode 100755 index 0000000..7e65cb7 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/dir.spec @@ -0,0 +1,771 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + P9K_HOME="${PWD}" +} + +function tearDown() { + unset P9K_HOME +} + +function testDirPathAbsoluteWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_ABSOLUTE=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + cd ~ + + # Unfortunately, we cannot fake Linux or OSX here, because + # of /home or /Users path.. That is why we change the test + # according to the OS of the host. + if [[ "${OS}" == 'Linux' ]]; then + assertEquals "%K{004} %F{000}/home/${USER} %k%F{004}%f " "$(build_left_prompt)" + elif [[ "${OS}" == 'OSX' ]]; then + assertEquals "%K{004} %F{000}/Users/${USER} %k%F{004}%f " "$(build_left_prompt)" + fi + + cd - +} + +function testTruncateFoldersWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + mkdir -p $FOLDER + cd $FOLDER + + assertEquals "%K{004} %F{000}…/12345678/123456789 %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +function testTruncateFolderWithHomeDirWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 + local CURRENT_DIR=$(pwd) + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + cd ~ + local FOLDER="powerlevel9k-test-${RANDOM}" + mkdir -p $FOLDER + cd $FOLDER + # Switch back to home folder as this causes the problem. + cd .. + + assertEquals "%K{004} %F{000}~ %k%F{004}%f " "$(build_left_prompt)" + + rmdir $FOLDER + cd ${CURRENT_DIR} +} + +function testTruncateMiddleWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + mkdir -p $FOLDER + cd $FOLDER + + assertEquals "%K{004} %F{000}/tmp/po…st/1/12/123/1234/12…45/12…56/12…67/12…78/123456789 %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +function testTruncationFromRightWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + mkdir -p $FOLDER + cd $FOLDER + + assertEquals "%K{004} %F{000}/tmp/po…/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +function testTruncateToLastWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_last" + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + mkdir -p $FOLDER + cd $FOLDER + + assertEquals "%K{004} %F{000}123456789 %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +function testTruncateToFirstAndLastWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_first_and_last" + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + mkdir -p $FOLDER + cd $FOLDER + + assertEquals "%K{004} %F{000}/tmp/powerlevel9k-test/…/…/…/…/…/…/…/12345678/123456789 %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +function testTruncateAbsoluteWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_absolute" + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + mkdir -p $FOLDER + cd $FOLDER + + assertEquals "%K{004} %F{000}…89 %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +function testTruncationFromRightWithEmptyDelimiter() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_DELIMITER="" + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + mkdir -p $FOLDER + cd $FOLDER + + assertEquals "%K{004} %F{000}/tmp/po/1/12/123/12/12/12/12/12/123456789 %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +function testTruncateWithFolderMarkerWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker" + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local BASEFOLDER=/tmp/powerlevel9k-test + local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567 + mkdir -p $FOLDER + # Setup folder marker + touch $BASEFOLDER/1/12/.shorten_folder_marker + cd $FOLDER + assertEquals "%K{004} %F{000}/…/12/123/1234/12345/123456/1234567 %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr $BASEFOLDER +} + +function testTruncateWithFolderMarkerWithChangedFolderMarker() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker" + local POWERLEVEL9K_SHORTEN_FOLDER_MARKER='.xxx' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local BASEFOLDER=/tmp/powerlevel9k-test + local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567 + mkdir -p $FOLDER + # Setup folder marker + touch $BASEFOLDER/1/12/.xxx + cd $FOLDER + assertEquals "%K{004} %F{000}/…/12/123/1234/12345/123456/1234567 %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr $BASEFOLDER +} + +function testTruncateWithPackageNameWorks() { + local p9kFolder=$(pwd) + local BASEFOLDER=/tmp/powerlevel9k-test + local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567/12345678/123456789 + mkdir -p $FOLDER + + cd /tmp/powerlevel9k-test + echo ' +{ + "name": "My_Package" +} +' > package.json + # Unfortunately: The main folder must be a git repo.. + git init &>/dev/null + + # Go back to deeper folder + cd "${FOLDER}" + + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{004} %F{000}My_Package/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{004}%f " "$(build_left_prompt)" + + # Go back + cd $p9kFolder + rm -fr $BASEFOLDER +} + +function testTruncateWithPackageNameIfRepoIsSymlinkedInsideDeepFolder() { + local p9kFolder=$(pwd) + local BASEFOLDER=/tmp/powerlevel9k-test + local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567/12345678/123456789 + mkdir -p $FOLDER + cd $FOLDER + + # Unfortunately: The main folder must be a git repo.. + git init &>/dev/null + + echo ' +{ + "name": "My_Package" +} +' > package.json + + # Create a subdir inside the repo + mkdir -p asdfasdf/qwerqwer + + cd $BASEFOLDER + ln -s ${FOLDER} linked-repo + + # Go to deep folder inside linked repo + cd linked-repo/asdfasdf/qwerqwer + + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{004} %F{000}My_Package/as…/qwerqwer %k%F{004}%f " "$(build_left_prompt)" + + # Go back + cd $p9kFolder + rm -fr $BASEFOLDER +} + +function testTruncateWithPackageNameIfRepoIsSymlinkedInsideGitDir() { + local p9kFolder=$(pwd) + local BASEFOLDER=/tmp/powerlevel9k-test + local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567/12345678/123456789 + mkdir -p $FOLDER + cd $FOLDER + + # Unfortunately: The main folder must be a git repo.. + git init &>/dev/null + + echo ' +{ + "name": "My_Package" +} +' > package.json + + cd $BASEFOLDER + ln -s ${FOLDER} linked-repo + + cd linked-repo/.git/refs/heads + + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{004} %F{000}My_Package/.g…/re…/heads %k%F{004}%f " "$(build_left_prompt)" + + # Go back + cd $p9kFolder + rm -fr $BASEFOLDER +} + +function testHomeFolderDetectionWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_HOME_ICON='home-icon' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + cd ~ + assertEquals "%K{004} %F{000}home-icon %f%F{000}~ %k%F{004}%f " "$(build_left_prompt)" + + cd - +} + +function testHomeSubfolderDetectionWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_HOME_SUB_ICON='sub-icon' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local FOLDER=~/powerlevel9k-test + mkdir $FOLDER + cd $FOLDER + assertEquals "%K{004} %F{000}sub-icon %f%F{000}~/powerlevel9k-test %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr $FOLDER +} + +function testOtherFolderDetectionWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_FOLDER_ICON='folder-icon' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local FOLDER=/tmp/powerlevel9k-test + mkdir $FOLDER + cd $FOLDER + assertEquals "%K{004} %F{000}folder-icon %f%F{000}/tmp/powerlevel9k-test %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr $FOLDER +} + +function testChangingDirPathSeparator() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local FOLDER="/tmp/powerlevel9k-test/1/2" + mkdir -p $FOLDER + cd $FOLDER + + assertEquals "%K{004} %F{000}xXxtmpxXxpowerlevel9k-testxXx1xXx2 %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +function testHomeFolderAbbreviation() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local dir=$PWD + + cd ~/ + # default + local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{004} %F{000}~ %k%F{004}%f " "$(build_left_prompt)" + + # substituted + local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{004} %F{000}qQq %k%F{004}%f " "$(build_left_prompt)" + + cd /tmp + # default + local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{004} %F{000}/tmp %k%F{004}%f " "$(build_left_prompt)" + + # substituted + local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{004} %F{000}/tmp %k%F{004}%f " "$(build_left_prompt)" + + cd "$dir" +} + +function testOmittingFirstCharacterWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_FOLDER_ICON='folder-icon' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + cd /tmp + + assertEquals "%K{004} %F{000}folder-icon %f%F{000}tmp %k%F{004}%f " "$(build_left_prompt)" + + cd - +} + +function testOmittingFirstCharacterWorksWithChangingPathSeparator() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local POWERLEVEL9K_FOLDER_ICON='folder-icon' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + mkdir -p /tmp/powerlevel9k-test/1/2 + cd /tmp/powerlevel9k-test/1/2 + + assertEquals "%K{004} %F{000}folder-icon %f%F{000}tmpxXxpowerlevel9k-testxXx1xXx2 %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +# This test makes it obvious that combining a truncation strategy +# that cuts off folders from the left and omitting the the first +# character does not make much sense. The truncation strategy +# comes first, prints an ellipsis and that gets then cut off by +# POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER.. +# But it does more sense in combination with other truncation +# strategies. +function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndDefaultTruncation() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + mkdir -p /tmp/powerlevel9k-test/1/2 + cd /tmp/powerlevel9k-test/1/2 + + assertEquals "%K{004} %F{000}xXx1xXx2 %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndMiddleTruncation() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + mkdir -p /tmp/powerlevel9k-test/1/2 + cd /tmp/powerlevel9k-test/1/2 + + assertEquals "%K{004} %F{000}tmpxXxpo…stxXx1xXx2 %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncation() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + mkdir -p /tmp/powerlevel9k-test/1/2 + cd /tmp/powerlevel9k-test/1/2 + + assertEquals "%K{004} %F{000}tmpxXxpo…xXx1xXx2 %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +function testTruncateToUniqueWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_to_unique' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + mkdir -p /tmp/powerlevel9k-test/adam/devl + mkdir -p /tmp/powerlevel9k-test/alice/devl + mkdir -p /tmp/powerlevel9k-test/alice/docs + mkdir -p /tmp/powerlevel9k-test/bob/docs + cd /tmp/powerlevel9k-test/alice/devl + + assertEquals "%K{004} %F{000}txXxpxXxalxXxde %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +function testBoldHomeDirWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + cd ~ + + assertEquals "%K{004} %F{000}%B~%b %k%F{004}%f " "$(build_left_prompt)" + + cd - +} + +function testBoldHomeSubdirWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + mkdir -p ~/powerlevel9k-test + cd ~/powerlevel9k-test + + assertEquals "%K{004} %F{000}~/%Bpowerlevel9k-test%b %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr ~/powerlevel9k-test +} + +function testBoldRootDirWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + cd / + + assertEquals "%K{004} %F{000}%B/%b %k%F{004}%f " "$(build_left_prompt)" + + cd - +} + +function testBoldRootSubdirWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + cd /tmp + + assertEquals "%K{004} %F{000}/%Btmp%b %k%F{004}%f " "$(build_left_prompt)" + + cd - +} + +function testBoldRootSubSubdirWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + mkdir -p /tmp/powerlevel9k-test + cd /tmp/powerlevel9k-test + + assertEquals "%K{004} %F{000}/tmp/%Bpowerlevel9k-test%b %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +function testHighlightHomeWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + cd ~ + + assertEquals "%K{004} %F{000}%F{red}~ %k%F{004}%f " "$(build_left_prompt)" + + cd - +} + +function testHighlightHomeSubdirWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + mkdir -p ~/powerlevel9k-test + cd ~/powerlevel9k-test + + assertEquals "%K{004} %F{000}~/%F{red}powerlevel9k-test %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr ~/powerlevel9k-test +} + +function testHighlightRootWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + cd / + + assertEquals "%K{004} %F{000}%F{red}/ %k%F{004}%f " "$(build_left_prompt)" + + cd - +} + +function testHighlightRootSubdirWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + cd /tmp + + assertEquals "%K{004} %F{000}/%F{red}tmp %k%F{004}%f " "$(build_left_prompt)" + + cd - +} + +function testHighlightRootSubSubdirWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + mkdir /tmp/powerlevel9k-test + cd /tmp/powerlevel9k-test + + assertEquals "%K{004} %F{000}/tmp/%F{red}powerlevel9k-test %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +function testDirSeparatorColorHomeSubdirWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + mkdir -p ~/powerlevel9k-test + cd ~/powerlevel9k-test + + assertEquals "%K{004} %F{000}~%F{red}/%F{black}powerlevel9k-test %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr ~/powerlevel9k-test +} + +function testDirSeparatorColorRootSubSubdirWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + mkdir -p /tmp/powerlevel9k-test + cd /tmp/powerlevel9k-test + + assertEquals "%K{004} %F{000}%F{red}/%F{black}tmp%F{red}/%F{black}powerlevel9k-test %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test +} + +source shunit2/shunit2 diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/disk_usage.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/disk_usage.spec new file mode 100755 index 0000000..ebafe31 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/disk_usage.spec @@ -0,0 +1,131 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + # Test specific + P9K_HOME=$(pwd) + FOLDER=/tmp/powerlevel9k-test + mkdir -p $FOLDER + cd $FOLDER +} + +function tearDown() { + # Go back to powerlevel9k folder + cd "${P9K_HOME}" + # Remove eventually created test-specific folder + rm -fr "${FOLDER}" + # At least remove test folder completely + rm -fr /tmp/powerlevel9k-test + unset FOLDER + unset P9K_HOME + + # Remove IP cache file + rm -f ${POWERLEVEL9K_PUBLIC_IP_FILE} +} + +function testDiskUsageSegmentWhenDiskIsAlmostFull() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage) + df() { + echo "Filesystem 1K-blocks Used Available Use% Mounted on +/dev/disk1 487219288 471466944 15496344 97% /" + } + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{001} %F{007}hdd %f%F{007}97%% %k%F{001}%f " "$(build_left_prompt)" + + unfunction df +} + +function testDiskUsageSegmentWhenDiskIsVeryFull() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage) + df() { + echo "Filesystem 1K-blocks Used Available Use% Mounted on +/dev/disk1 487219288 471466944 15496344 94% /" + } + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{003} %F{000}hdd %f%F{000}94%% %k%F{003}%f " "$(build_left_prompt)" + + unfunction df +} + +function testDiskUsageSegmentWhenDiskIsQuiteEmpty() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage) + df() { + echo "Filesystem 1K-blocks Used Available Use% Mounted on +/dev/disk1 487219288 471466944 15496344 4% /" + } + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{003}hdd %f%F{003}4%% %k%F{000}%f " "$(build_left_prompt)" + + unfunction df +} + +function testDiskUsageSegmentPrintsNothingIfDiskIsQuiteEmptyAndOnlyWarningsShouldBeDisplayed() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage custom_world) + df() { + echo "Filesystem 1K-blocks Used Available Use% Mounted on +/dev/disk1 487219288 471466944 15496344 4% /" + } + + local POWERLEVEL9K_DISK_USAGE_ONLY_WARNING=true + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unfunction df +} + +function testDiskUsageSegmentWarningLevelCouldBeAdjusted() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage) + local POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL=10 + df() { + echo "Filesystem 1K-blocks Used Available Use% Mounted on +/dev/disk1 487219288 471466944 15496344 11% /" + } + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{003} %F{000}hdd %f%F{000}11%% %k%F{003}%f " "$(build_left_prompt)" + + unfunction df +} + +function testDiskUsageSegmentCriticalLevelCouldBeAdjusted() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage) + local POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL=5 + local POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL=10 + df() { + echo "Filesystem 1K-blocks Used Available Use% Mounted on +/dev/disk1 487219288 471466944 15496344 11% /" + } + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{001} %F{007}hdd %f%F{007}11%% %k%F{001}%f " "$(build_left_prompt)" + + unfunction df +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/go_version.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/go_version.spec new file mode 100755 index 0000000..d7a1c2c --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/go_version.spec @@ -0,0 +1,88 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" +} + +function mockGo() { + case "$1" in + 'version') + echo 'go version go1.5.3 darwin/amd64' + ;; + 'env') + echo "$HOME/go" + ;; + esac +} + +function mockGoEmptyGopath() { + case "$1" in + 'version') + echo 'go version go1.5.3 darwin/amd64' + ;; + 'env') + echo "" + ;; + esac +} + +function testGo() { + alias go=mockGo + local POWERLEVEL9K_GO_ICON="" + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(go_version) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + local PWD="$HOME/go/src/github.com/bhilburn/powerlevel9k" + + assertEquals "%K{002} %F{255} %f%F{255}go1.5.3 %k%F{002}%f " "$(build_left_prompt)" + + unalias go +} + +function testGoSegmentPrintsNothingIfEmptyGopath() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + alias go=mockGoEmptyGopath + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +function testGoSegmentPrintsNothingIfNotInGopath() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + alias go=mockGo + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +function testGoSegmentPrintsNothingIfGoIsNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + alias go=noGo + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unalias go +} + +source shunit2/shunit2 diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/ip.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/ip.spec new file mode 100755 index 0000000..254f11c --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/ip.spec @@ -0,0 +1,231 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" +} + +function testIpSegmentPrintsNothingOnOsxIfNotConnected() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip custom_world) + alias networksetup='echo "not connected"' + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS="OSX" # Fake OSX + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unalias networksetup +} + +function testIpSegmentPrintsNothingOnLinuxIfNotConnected() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip custom_world) + alias ip='echo "not connected"' + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS="Linux" # Fake Linux + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unalias ip +} + +function testIpSegmentWorksOnOsxWithNoInterfaceSpecified() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) + alias networksetup="echo 'An asterisk (*) denotes that a network service is disabled. +(1) Ethernet +(Hardware Port: Ethernet, Device: en0) + +(2) FireWire +(Hardware Port: FireWire, Device: fw0) + +(3) Wi-Fi +(Hardware Port: Wi-Fi, Device: en1) + +(4) Bluetooth PAN +(Hardware Port: Bluetooth PAN, Device: en3) + +(5) Thunderbolt Bridge +(Hardware Port: Thunderbolt Bridge, Device: bridge0) + +(6) Apple USB Ethernet Adapter +(Hardware Port: Apple USB Ethernet Adapter, Device: en4) +'" + + alias ipconfig="_(){ echo '1.2.3.4'; };_" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS='OSX' # Fake OSX + + assertEquals "%K{006} %F{000}IP %f%F{000}1.2.3.4 %k%F{006}%f " "$(build_left_prompt)" + + unalias ipconfig + unalias networksetup +} + +# There could be more than one confiured network interfaces. +# `networksetup -listnetworkserviceorder` lists the interfaces +# in hierarchical order, but from outside this is not obvious +# (implementation detail). So we need a test for this case. +function testIpSegmentWorksOnOsxWithMultipleInterfacesSpecified() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) + alias networksetup="echo 'An asterisk (*) denotes that a network service is disabled. +(1) Ethernet +(Hardware Port: Ethernet, Device: en0) + +(2) FireWire +(Hardware Port: FireWire, Device: fw0) + +(3) Wi-Fi +(Hardware Port: Wi-Fi, Device: en1) + +(4) Bluetooth PAN +(Hardware Port: Bluetooth PAN, Device: en3) + +(5) Thunderbolt Bridge +(Hardware Port: Thunderbolt Bridge, Device: bridge0) + +(6) Apple USB Ethernet Adapter +(Hardware Port: Apple USB Ethernet Adapter, Device: en4) +'" + + # Return a unique IP address for every interface + ipconfig() { + case "${2}" { + en0) + echo 1.2.3.4 + ;; + fw0) + echo 2.3.4.5 + ;; + en1) + echo 3.4.5.6 + ;; + en3) + echo 4.5.6.7 + ;; + } + } + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS='OSX' # Fake OSX + + assertEquals "%K{006} %F{000}IP %f%F{000}1.2.3.4 %k%F{006}%f " "$(build_left_prompt)" + + unfunction ipconfig + unalias networksetup +} + +function testIpSegmentWorksOnOsxWithInterfaceSpecified() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) + local POWERLEVEL9K_IP_INTERFACE='xxx' + alias ipconfig="_(){ echo '1.2.3.4'; };_" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS='OSX' # Fake OSX + + assertEquals "%K{006} %F{000}IP %f%F{000}1.2.3.4 %k%F{006}%f " "$(build_left_prompt)" + + unalias ipconfig +} + +function testIpSegmentWorksOnLinuxWithNoInterfaceSpecified() { + setopt aliases + local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) + # That command is harder to test, as it is used at first + # to get all relevant network interfaces and then for + # getting the configuration of that segment.. + ip(){ + if [[ "$*" == 'link ls up' ]]; then + echo "1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default + link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 +2: eth0: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 + link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff"; + fi + + if [[ "$*" == '-4 a show eth0' ]]; then + echo '2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 + inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 + valid_lft forever preferred_lft forever'; + fi + } + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS='Linux' # Fake Linux + + assertEquals "%K{006} %F{000}IP %f%F{000}10.0.2.15 %k%F{006}%f " "$(build_left_prompt)" + + unfunction ip +} + +function testIpSegmentWorksOnLinuxWithMultipleInterfacesSpecified() { + setopt aliases + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) + # That command is harder to test, as it is used at first + # to get all relevant network interfaces and then for + # getting the configuration of that segment.. + ip(){ + if [[ "$*" == 'link ls up' ]]; then + echo "1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default + link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 +2: eth0: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 + link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff +3: eth1: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 + link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff +4: wlan0: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 + link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff"; + fi + + if [[ "$*" == '-4 a show eth1' ]]; then + echo '3: eth1: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 + inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 + valid_lft forever preferred_lft forever'; + fi + } + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS='Linux' # Fake Linux + + assertEquals "%K{006} %F{000}IP %f%F{000}10.0.2.15 %k%F{006}%f " "$(build_left_prompt)" + + unfunction ip +} + +function testIpSegmentWorksOnLinuxWithInterfaceSpecified() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) + local POWERLEVEL9K_IP_INTERFACE='xxx' + ip(){ + echo '2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 +inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 + valid_lft forever preferred_lft forever'; + } + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS='Linux' # Fake Linux + + assertEquals "%K{006} %F{000}IP %f%F{000}10.0.2.15 %k%F{006}%f " "$(build_left_prompt)" + + unfunction ip +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/kubecontext.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/kubecontext.spec new file mode 100755 index 0000000..76b35c3 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/kubecontext.spec @@ -0,0 +1,104 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" +} + +function mockKubectl() { + case "$1" in + 'version') + echo 'non-empty text' + ;; + 'config') + case "$2" in + 'view') + case "$3" in + '-o=jsonpath={.current-context}') + echo 'minikube' + ;; + '-o=jsonpath={.contexts'*) + echo '' + ;; + *) + echo "Mock value missed" + exit 1 + ;; + esac + ;; + esac + ;; + esac +} + +function mockKubectlOtherNamespace() { + case "$1" in + 'version') + echo 'non-empty text' + ;; + 'config') + case "$2" in + 'view') + case "$3" in + # Get Current Context + '-o=jsonpath={.current-context}') + echo 'minikube' + ;; + # Get current namespace + '-o=jsonpath={.contexts'*) + echo 'kube-system' + ;; + *) + echo "Mock value missed" + exit 1 + ;; + esac + ;; + esac + ;; + esac +} + +function testKubeContext() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) + alias kubectl=mockKubectl + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{005} %F{007}⎈ %f%F{007}minikube/default %k%F{005}%f " "$(build_left_prompt)" + + unalias kubectl +} +function testKubeContextOtherNamespace() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) + alias kubectl=mockKubectlOtherNamespace + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{005} %F{007}⎈ %f%F{007}minikube/kube-system %k%F{005}%f " "$(build_left_prompt)" + + unalias kubectl +} +function testKubeContextPrintsNothingIfKubectlNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world kubecontext) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + alias kubectl=noKubectl + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unalias kubectl +} + +source shunit2/shunit2 diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/laravel_version.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/laravel_version.spec new file mode 100755 index 0000000..c4f09e5 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/laravel_version.spec @@ -0,0 +1,72 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" +} + +function mockLaravelVersion() { + case "$1" in + "artisan") + # artisan --version follows the format Laravel Framework + echo "Laravel Framework 5.4.23" + ;; + default) + esac +} + +function mockNoLaravelVersion() { + # When php can't find a file it will output a message + echo "Could not open input file: artisan" + return 0 +} + +function testLaravelVersionSegment() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(laravel_version) + local POWERLEVEL9K_LARAVEL_ICON='x' + alias php=mockLaravelVersion + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{009} %F{007}x %f%F{007}5.4.23 %k%F{009}%f " "$(build_left_prompt)" + + unalias php +} + +function testLaravelVersionSegmentIfArtisanIsNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world laravel_version) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + local POWERLEVEL9K_LARAVEL_ICON='x' + alias php=mockNoLaravelVersion + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unalias php +} + +function testLaravelVersionSegmentPrintsNothingIfPhpIsNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world laravel_version) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + local POWERLEVEL9K_LARAVEL_ICON='x' + alias php=noPhp + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unalias php +} + +source shunit2/shunit2 diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/load.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/load.spec new file mode 100755 index 0000000..0f8ee33 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/load.spec @@ -0,0 +1,149 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + P9K_HOME=$(pwd) + ### Test specific + # Create default folder and git init it. + FOLDER=/tmp/powerlevel9k-test/load-test + mkdir -p "${FOLDER}" + cd $FOLDER +} + +function tearDown() { + # Go back to powerlevel9k folder + cd "${P9K_HOME}" + # Remove eventually created test-specific folder + rm -fr "${FOLDER}" + # At least remove test folder completely + rm -fr /tmp/powerlevel9k-test +} + +function testLoadSegmentWorksOnOsx() { + sysctl() { + if [[ "$*" == 'vm.loadavg' ]]; then + echo "vm.loadavg: { 1,38 1,45 2,16 }"; + fi + + if [[ "$*" == '-n hw.logicalcpu' ]]; then + echo "4"; + fi + } + + local POWERLEVEL9K_LOAD_WHICH=1 + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="OSX" # Fake OSX + + assertEquals "%K{002} %F{000}L %f%F{000}1.38 " "$(prompt_load left 1 false ${FOLDER})" + + unfunction sysctl +} + +function testLoadSegmentWorksOnBsd() { + sysctl() { + if [[ "$*" == 'vm.loadavg' ]]; then + echo "vm.loadavg: { 1,38 1,45 2,16 }"; + fi + + if [[ "$*" == '-n hw.ncpu' ]]; then + echo "4"; + fi + } + + local POWERLEVEL9K_LOAD_WHICH=1 + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="BSD" # Fake BSD + + assertEquals "%K{002} %F{000}L %f%F{000}1.38 " "$(prompt_load left 1 false ${FOLDER})" + + unfunction sysctl +} + +function testLoadSegmentWorksOnLinux() { + # Prepare loadavg + mkdir proc + echo "1.38 0.01 0.05 1/87 8641" > proc/loadavg + + alias nproc="echo 4" + local POWERLEVEL9K_LOAD_WHICH=1 + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="Linux" # Fake Linux + + assertEquals "%K{002} %F{000}L %f%F{000}1.38 " "$(prompt_load left 1 false ${FOLDER})" + + unalias nproc +} + +# Test normal state. This test is not OS specific. +# We test it as the Linux version, but that +# does not matter here. +function testLoadSegmentNormalState() { + # Prepare loadavg + mkdir proc + echo "1.00 0.01 0.05 1/87 8641" > proc/loadavg + + alias nproc="echo 4" + local POWERLEVEL9K_LOAD_WHICH=1 + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="Linux" # Fake Linux + + assertEquals "%K{002} %F{000}L %f%F{000}1.00 " "$(prompt_load left 1 false ${FOLDER})" + + unalias nproc +} + +# Test warning state. This test is not OS specific. +# We test it as the Linux version, but that +# does not matter here. +function testLoadSegmentWarningState() { + # Prepare loadavg + mkdir proc + echo "2.01 0.01 0.05 1/87 8641" > proc/loadavg + + alias nproc="echo 4" + local POWERLEVEL9K_LOAD_WHICH=1 + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="Linux" # Fake Linux + + assertEquals "%K{003} %F{000}L %f%F{000}2.01 " "$(prompt_load left 1 false ${FOLDER})" + + unalias nproc +} + +# Test critical state. This test is not OS specific. +# We test it as the Linux version, but that +# does not matter here. +function testLoadSegmentCriticalState() { + # Prepare loadavg + mkdir proc + echo "2.81 0.01 0.05 1/87 8641" > proc/loadavg + + alias nproc="echo 4" + local POWERLEVEL9K_LOAD_WHICH=1 + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="Linux" # Fake Linux + + assertEquals "%K{001} %F{000}L %f%F{000}2.81 " "$(prompt_load left 1 false ${FOLDER})" + + unalias nproc +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/node_version.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/node_version.spec new file mode 100755 index 0000000..69b9cbb --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/node_version.spec @@ -0,0 +1,41 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" +} + +function testNodeVersionSegmentPrintsNothingWithoutNode() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(node_version custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + alias node="nonode 2>/dev/null" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unalias node +} + +function testNodeVersionSegmentWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(node_version) + node() { + echo "v1.2.3" + } + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{007}⬢ %f%F{007}1.2.3 %k%F{002}%f " "$(build_left_prompt)" + + unfunction node +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/nodeenv.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/nodeenv.spec new file mode 100755 index 0000000..2e9d779 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/nodeenv.spec @@ -0,0 +1,99 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + # Test specfic + # unset all possible user specified variables + unset NODE_VIRTUAL_ENV_DISABLE_PROMPT + unset NODE_VIRTUAL_ENV +} + +function testNodeenvSegmentPrintsNothingWithoutNode() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + alias node="nonode 2>/dev/null" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unalias node +} + +function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvIsNotSet() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + node() { + echo "v1.2.3" + } + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unfunction node +} + +function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvDisablePromptIsSet() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + node() { + echo "v1.2.3" + } + NODE_VIRTUAL_ENV="node-env" + NODE_VIRTUAL_ENV_DISABLE_PROMPT=true + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unset NODE_VIRTUAL_ENV_DISABLE_PROMPT + unset NODE_VIRTUAL_ENV + unfunction node +} + +function testNodeenvSegmentPrintsAtLeastNodeEnvWithoutNode() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv) + alias node="nonode 2>/dev/null" + NODE_VIRTUAL_ENV="node-env" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{002}⬢ %f%F{002}[node-env] %k%F{000}%f " "$(build_left_prompt)" + + unset NODE_VIRTUAL_ENV + unalias node +} + +function testNodeenvSegmentWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv) + node() { + echo "v1.2.3" + } + NODE_VIRTUAL_ENV="node-env" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{002}⬢ %f%F{002}v1.2.3[node-env] %k%F{000}%f " "$(build_left_prompt)" + + unfunction node + unset NODE_VIRTUAL_ENV +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/nvm.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/nvm.spec new file mode 100755 index 0000000..c9ed430 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/nvm.spec @@ -0,0 +1,72 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + P9K_HOME=$(pwd) + ### Test specific + # Create default folder and git init it. + FOLDER=/tmp/powerlevel9k-test/nvm-test + mkdir -p "${FOLDER}/bin" + OLD_PATH=$PATH + PATH=${FOLDER}/bin:$PATH + cd $FOLDER +} + +function tearDown() { + # Restore old path + PATH="${OLD_PATH}" + # Go back to powerlevel9k folder + cd "${P9K_HOME}" + # Remove eventually created test-specific folder + rm -fr "${FOLDER}" + # At least remove test folder completely + rm -fr /tmp/powerlevel9k-test +} + +function testNvmSegmentPrintsNothingIfNvmIsNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +function testNvmSegmentWorksWithoutHavingADefaultAlias() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm) + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + function nvm_version() { + [[ ${1} == 'current' ]] && echo 'v4.6.0' || echo 'v1.4.0' + } + + assertEquals "%K{005} %F{000}⬢ %f%F{000}4.6.0 %k%F{005}%f " "$(build_left_prompt)" +} + +function testNvmSegmentPrintsNothingWhenOnDefaultVersion() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + function nvm_version() { + [[ ${1} == 'current' ]] && echo 'v4.6.0' || echo 'v4.6.0' + } + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/php_version.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/php_version.spec new file mode 100755 index 0000000..6d64c57 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/php_version.spec @@ -0,0 +1,42 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" +} + +function testPhpVersionSegmentPrintsNothingIfPhpIsNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(php_version custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + alias php="nophp" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unalias php +} + +function testPhpVersionSegmentWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(php_version) + alias php="echo 'PHP 5.6.27 (cli) (built: Oct 23 2016 11:47:58) +Copyright (c) 1997-2016 The PHP Group +Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies +'" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{013} %F{255}PHP 5.6.27 %k%F{013}%f " "$(build_left_prompt)" + + unalias php +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/public_ip.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/public_ip.spec new file mode 100755 index 0000000..334a642 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/public_ip.spec @@ -0,0 +1,222 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + # Test specific + P9K_HOME=$(pwd) + FOLDER=/tmp/powerlevel9k-test + mkdir -p $FOLDER + cd $FOLDER + + # Change cache file, so that the users environment don't + # interfere with the tests. + POWERLEVEL9K_PUBLIC_IP_FILE=$FOLDER/public_ip_file +} + +function tearDown() { + # Go back to powerlevel9k folder + cd "${P9K_HOME}" + # Remove eventually created test-specific folder + rm -fr "${FOLDER}" + # At least remove test folder completely + rm -fr /tmp/powerlevel9k-test + unset FOLDER + unset P9K_HOME + + # Unset cache file + unset POWERLEVEL9K_PUBLIC_IP_FILE +} + +function testPublicIpSegmentPrintsNothingByDefaultIfHostIsNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip custom_world) + local POWERLEVEL9K_PUBLIC_IP_HOST='http://unknown.xyz' + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + # We need to overwrite dig, as this is a fallback method that + # uses an alternative host. + alias dig='nodig' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unalias dig +} + +function testPublicIpSegmentPrintsNoticeIfNotConnected() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + local POWERLEVEL9K_PUBLIC_IP_HOST='http://unknown.xyz' + local POWERLEVEL9K_PUBLIC_IP_NONE="disconnected" + # We need to overwrite dig, as this is a fallback method that + # uses an alternative host. + alias dig='nodig' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{007}disconnected %k%F{000}%f " "$(build_left_prompt)" + + unalias dig +} + +function testPublicIpSegmentWorksWithWget() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + alias dig='nodig' + alias curl='nocurl' + wget() { + echo "wget 1.2.3.4" + } + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{007}wget 1.2.3.4 %k%F{000}%f " "$(build_left_prompt)" + + unfunction wget + unalias dig + unalias curl +} + +function testPublicIpSegmentUsesCurlAsFallbackMethodIfWgetIsNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + alias dig='nodig' + alias wget='nowget' + curl() { + echo "curl 1.2.3.4" + } + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{007}curl 1.2.3.4 %k%F{000}%f " "$(build_left_prompt)" + + unfunction curl + unalias dig + unalias wget +} + +function testPublicIpSegmentUsesDigAsFallbackMethodIfWgetAndCurlAreNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + alias curl='nocurl' + alias wget='nowget' + dig() { + echo "dig 1.2.3.4" + } + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{007}dig 1.2.3.4 %k%F{000}%f " "$(build_left_prompt)" + + unfunction dig + unalias curl + unalias wget +} + +function testPublicIpSegmentCachesFile() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + dig() { + echo "first" + } + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{007}first %k%F{000}%f " "$(build_left_prompt)" + + dig() { + echo "second" + } + + # Segment should not have changed! + assertEquals "%K{000} %F{007}first %k%F{000}%f " "$(build_left_prompt)" + + unfunction dig +} + +function testPublicIpSegmentRefreshesCachesFileAfterTimeout() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + local POWERLEVEL9K_PUBLIC_IP_TIMEOUT=2 + dig() { + echo "first" + } + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{007}first %k%F{000}%f " "$(build_left_prompt)" + + sleep 3 + dig() { + echo "second" + } + + # Segment should not have changed! + assertEquals "%K{000} %F{007}second %k%F{000}%f " "$(build_left_prompt)" + + unfunction dig +} + +function testPublicIpSegmentRefreshesCachesFileIfEmpty() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + dig() { + echo "first" + } + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{007}first %k%F{000}%f " "$(build_left_prompt)" + + # Truncate cache file + echo "" >! $POWERLEVEL9K_PUBLIC_IP_FILE + + dig() { + echo "second" + } + + # Segment should not have changed! + assertEquals "%K{000} %F{007}second %k%F{000}%f " "$(build_left_prompt)" + + unfunction dig +} + +function testPublicIpSegmentWhenGoingOnline() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + local POWERLEVEL9K_PUBLIC_IP_METHODS="dig" + local POWERLEVEL9K_PUBLIC_IP_NONE="disconnected" + alias dig="nodig" + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{007}disconnected %k%F{000}%f " "$(build_left_prompt)" + + unalias dig + + dig() { + echo "second" + } + + # Segment should not have changed! + assertEquals "%K{000} %F{007}second %k%F{000}%f " "$(build_left_prompt)" + + unfunction dig +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/ram.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/ram.spec new file mode 100755 index 0000000..2c9f169 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/ram.spec @@ -0,0 +1,66 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + P9K_HOME=$(pwd) + ### Test specific + # Create default folder and git init it. + FOLDER=/tmp/powerlevel9k-test/ram-test + mkdir -p "${FOLDER}" + cd $FOLDER +} + +function tearDown() { + # Go back to powerlevel9k folder + cd "${P9K_HOME}" + # Remove eventually created test-specific folder + rm -fr "${FOLDER}" + # At least remove test folder completely + rm -fr /tmp/powerlevel9k-test +} + +function testRamSegmentWorksOnOsx() { + alias vm_stat="echo 'Mach Virtual Memory Statistics: (page size of 4096 bytes) +Pages free: 299687. +Pages active: 1623792. +Pages inactive: 1313411. +'" + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="OSX" # Fake OSX + + assertEquals "%K{003} %F{000}RAM %f%F{000}6.15G " "$(prompt_ram left 1 false ${FOLDER})" + + unalias vm_stat +} + +function testRamSegmentWorksOnBsd() { + mkdir -p var/run + echo "avail memory 5678B 299687 4444G 299" > var/run/dmesg.boot + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="BSD" # Fake BSD + + assertEquals "%K{003} %F{000}RAM %f%F{000}0.29M " "$(prompt_ram left 1 false ${FOLDER})" +} + +function testRamSegmentWorksOnLinux() { + mkdir proc + echo "MemAvailable: 299687" > proc/meminfo + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="Linux" # Fake Linux + + assertEquals "%K{003} %F{000}RAM %f%F{000}0.29G " "$(prompt_ram left 1 false ${FOLDER})" +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/rust_version.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/rust_version.spec new file mode 100755 index 0000000..07331ed --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/rust_version.spec @@ -0,0 +1,51 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +TEST_BASE_FOLDER=/tmp/powerlevel9k-test +RUST_TEST_FOLDER="${TEST_BASE_FOLDER}/rust-test" + +function setUp() { + OLDPATH="${PATH}" + mkdir -p "${RUST_TEST_FOLDER}" + PATH="${RUST_TEST_FOLDER}:${PATH}" + + export TERM="xterm-256color" +} + +function tearDown() { + PATH="${OLDPATH}" + rm -fr "${TEST_BASE_FOLDER}" +} + +function mockRust() { + echo "#!/bin/sh\n\necho 'rustc 0.4.1a-alpha'" > "${RUST_TEST_FOLDER}/rustc" + chmod +x "${RUST_TEST_FOLDER}/rustc" +} + +function testRust() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version) + mockRust + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{208} %F{000}Rust %f%F{000}0.4.1a-alpha %k%F{208}%f " "$(build_left_prompt)" +} + +function testRustPrintsNothingIfRustIsNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world rust_version) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +source shunit2/shunit2 diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/ssh.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/ssh.spec new file mode 100755 index 0000000..3245231 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/ssh.spec @@ -0,0 +1,80 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" +} + +function testSshSegmentPrintsNothingIfNoSshConnection() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo "world"' + local POWERLEVEL9K_SSH_ICON="ssh-icon" + # Weak test: Emulate No SSH connection by unsetting + # $SSH_CLIENT and $SSH_TTY + unset SSH_CLIENT + unset SSH_TTY + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +function testSshSegmentWorksIfOnlySshClientIsSet() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh) + local POWERLEVEL9K_SSH_ICON="ssh-icon" + # Weak test: Emulate No SSH connection by unsetting + # $SSH_CLIENT and $SSH_TTY + SSH_CLIENT='ssh-client' + unset SSH_TTY + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{003}ssh-icon%f %k%F{000}%f " "$(build_left_prompt)" + + unset SSH_CLIENT +} + +function testSshSegmentWorksIfOnlySshTtyIsSet() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh) + local POWERLEVEL9K_SSH_ICON="ssh-icon" + # Weak test: Emulate No SSH connection by unsetting + # $SSH_CLIENT and $SSH_TTY + SSH_TTY='ssh-tty' + unset SSH_CLIENT + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{003}ssh-icon%f %k%F{000}%f " "$(build_left_prompt)" + + unset SSH_TTY +} + +function testSshSegmentWorksIfAllNecessaryVariablesAreSet() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh) + local POWERLEVEL9K_SSH_ICON="ssh-icon" + # Weak test: Emulate No SSH connection by unsetting + # $SSH_CLIENT and $SSH_TTY + SSH_CLIENT='ssh-client' + SSH_TTY='ssh-tty' + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{003}ssh-icon%f %k%F{000}%f " "$(build_left_prompt)" + + unset SSH_TTY + unset SSH_CLIENT +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/status.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/status.spec new file mode 100755 index 0000000..9fb34e0 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/status.spec @@ -0,0 +1,113 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + ### Test specific + # Resets if someone has set these in his/hers env + unset POWERLEVEL9K_STATUS_VERBOSE + unset POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE +} + +function testStatusPrintsNothingIfReturnCodeIsZeroAndVerboseIsUnset() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + local POWERLEVEL9K_STATUS_VERBOSE=false + local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +function testStatusWorksAsExpectedIfReturnCodeIsZeroAndVerboseIsSet() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) + local POWERLEVEL9K_STATUS_VERBOSE=true + local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false + local POWERLEVEL9K_STATUS_HIDE_SIGNAME=true + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{002}✔%f %k%F{000}%f " "$(build_left_prompt)" +} + +function testStatusInGeneralErrorCase() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) + local POWERLEVEL9K_STATUS_VERBOSE=true + local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local RETVAL=1 + + assertEquals "%K{001} %F{226}↵ %f%F{226}1 %k%F{001}%f " "$(build_left_prompt)" +} + +function testPipestatusInErrorCase() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) + local POWERLEVEL9K_STATUS_VERBOSE=true + local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=true + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local -a RETVALS + RETVALS=(0 0 1 0) + + assertEquals "%K{001} %F{226}↵ %f%F{226}0|0|1|0 %k%F{001}%f " "$(build_left_prompt)" +} + +function testStatusCrossWinsOverVerbose() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) + local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false + local POWERLEVEL9K_STATUS_VERBOSE=true + local POWERLEVEL9K_STATUS_CROSS=true + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local RETVAL=1 + + assertEquals "%K{000} %F{001}✘%f %k%F{000}%f " "$(build_left_prompt)" +} + +function testStatusShowsSignalNameInErrorCase() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) + local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false + local POWERLEVEL9K_STATUS_VERBOSE=true + local POWERLEVEL9K_STATUS_HIDE_SIGNAME=false + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local RETVAL=132 + + assertEquals "%K{001} %F{226}↵ %f%F{226}SIGILL(4) %k%F{001}%f " "$(build_left_prompt)" +} + +function testStatusSegmentIntegrated() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=() + local POWERLEVEL9K_STATUS_CROSS=true + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + false; powerlevel9k_prepare_prompts + + assertEquals "%f%b%k%K{000} %F{001}✘%f %k%F{000}%f " "${(e)PROMPT}" +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/swap.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/swap.spec new file mode 100755 index 0000000..7db5416 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/swap.spec @@ -0,0 +1,58 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + P9K_HOME=$(pwd) + ### Test specific + # Create default folder and git init it. + FOLDER=/tmp/powerlevel9k-test/swap-test + mkdir -p "${FOLDER}" + cd $FOLDER +} + +function tearDown() { + # Go back to powerlevel9k folder + cd "${P9K_HOME}" + # Remove eventually created test-specific folder + rm -fr "${FOLDER}" + # At least remove test folder completely + rm -fr /tmp/powerlevel9k-test +} + +function testSwapSegmentWorksOnOsx() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swap) + sysctl() { + echo "vm.swapusage: total = 3072,00M used = 1620,50M free = 1451,50M (encrypted)" + } + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="OSX" # Fake OSX + + assertEquals "%K{003} %F{000}SWP %f%F{000}1.58G " "$(prompt_swap left 1 false ${FOLDER})" + + unfunction sysctl +} + +function testSwapSegmentWorksOnLinux() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swap) + mkdir proc + echo "SwapTotal: 1000000" > proc/meminfo + echo "SwapFree: 1000" >> proc/meminfo + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="Linux" # Fake Linux + + assertEquals "%K{003} %F{000}SWP %f%F{000}0.95G " "$(prompt_swap left 1 false ${FOLDER})" +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/swift_version.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/swift_version.spec new file mode 100755 index 0000000..47fc0b7 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/swift_version.spec @@ -0,0 +1,57 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + P9K_HOME=$(pwd) + ### Test specific + # Create default folder and git init it. + FOLDER=/tmp/powerlevel9k-test + mkdir -p "${FOLDER}" + cd $FOLDER +} + +function tearDown() { + # Go back to powerlevel9k folder + cd "${P9K_HOME}" + # Remove eventually created test-specific folder + rm -fr "${FOLDER}" + # At least remove test folder completely + rm -fr /tmp/powerlevel9k-test +} + +function testSwiftSegmentPrintsNothingIfSwiftIsNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swift_version custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + alias swift="noswift" + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unalias swift +} + +function testSwiftSegmentWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swift_version) + function swift() { + echo "Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1)\nTarget: x86_64-apple-macosx10.9" + } + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{005} %F{007}Swift %f%F{007}3.0.1 %k%F{005}%f " "$(build_left_prompt)" + + unfunction swift +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/symfony_version.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/symfony_version.spec new file mode 100755 index 0000000..cb48072 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/symfony_version.spec @@ -0,0 +1,117 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + P9K_HOME=$(pwd) + ### Test specific + # Create default folder and git init it. + FOLDER=/tmp/powerlevel9k-test + mkdir -p "${FOLDER}" + cd $FOLDER +} + +function tearDown() { + # Go back to powerlevel9k folder + cd "${P9K_HOME}" + # Remove eventually created test-specific folder + rm -fr "${FOLDER}" + # At least remove test folder completely + rm -fr /tmp/powerlevel9k-test +} + +function testSymfonyVersionSegmentPrintsNothingIfPhpIsNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + alias php="nophp" + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unalias php +} + +function testSymfonyVersionSegmentPrintsNothingIfSymfonyIsNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version custom_world) + # "Symfony" is not a command, but rather a framework. + # To sucessfully execute this test, we just need to + # navigate into a folder that does not contain symfony. + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +function testSymfonyVersionPrintsNothingIfPhpThrowsAnError() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + mkdir app + touch app/AppKernel.php + function php() { + echo "Warning: Unsupported declare strict_types in /Users/dr/Privat/vendor/ocramius/proxy-manager/src/ProxyManager/Configuration.php on line 19 + + Parse error: parse error, expecting `;´ or `{´ in /Users/dr/Privat/vendor/ocramius/proxy-manager/src/ProxyManager/Configuration.php on line 97" + } + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" + + unfunction php +} + +function testSymfonyVersionSegmentWorks() { + startSkipping # Skip test + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version) + mkdir app + touch app/AppKernel.php + + function php() { + echo "Symfony version 3.1.4 - app/dev/debug" + } + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{240} %F{000}SF %f%F{000}3.1.4 %k%F{240}%f " "$(build_left_prompt)" + + unfunction php +} + +function testSymfonyVersionSegmentWorksInNestedFolder() { + startSkipping # Skip test + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version) + mkdir app + touch app/AppKernel.php + + function php() { + echo "Symfony version 3.1.4 - app/dev/debug" + } + + mkdir -p src/P9K/AppBundle + cd src/P9K/AppBundle + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{240} %F{000}SF %f%F{000}3.1.4 %k%F{240}%f " "$(build_left_prompt)" + + unfunction php +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/todo.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/todo.spec new file mode 100755 index 0000000..875c45f --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/todo.spec @@ -0,0 +1,58 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + P9K_HOME=$(pwd) + ### Test specific + # Create default folder and git init it. + FOLDER=/tmp/powerlevel9k-test + mkdir -p "${FOLDER}" + mkdir ${FOLDER}/bin + OLD_PATH=$PATH + PATH=${FOLDER}/bin:$PATH + cd $FOLDER +} + +function tearDown() { + # Reset PATH + PATH=$OLD_PATH + # Go back to powerlevel9k folder + cd "${P9K_HOME}" + # Remove eventually created test-specific folder + rm -fr "${FOLDER}" + # At least remove test folder completely + rm -fr /tmp/powerlevel9k-test +} + +function testTodoSegmentPrintsNothingIfTodoShIsNotInstalled() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(todo custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" +} + +function testTodoSegmentWorksAsExpected() { + # TODO: Skript in den PATH legen! + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(todo) + echo '#!/bin/sh' > ${FOLDER}/bin/todo.sh + echo 'echo "TODO: 34 of 100 tasks shown";' >> ${FOLDER}/bin/todo.sh + chmod +x ${FOLDER}/bin/todo.sh + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{244} %F{000}☑ %f%F{000}100 %k%F{244}%f " "$(build_left_prompt)" +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/vcs-git.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/vcs-git.spec new file mode 100755 index 0000000..17a277f --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/vcs-git.spec @@ -0,0 +1,493 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + P9K_HOME=$(pwd) + ### Test specific + # Create default folder and git init it. + FOLDER=/tmp/powerlevel9k-test/vcs-test + mkdir -p "${FOLDER}" + cd $FOLDER + + # Set username and email + OLD_GIT_AUTHOR_NAME=$GIT_AUTHOR_NAME + GIT_AUTHOR_NAME="Testing Tester" + OLD_GIT_AUTHOR_EMAIL=$GIT_AUTHOR_EMAIL + GIT_AUTHOR_EMAIL="test@powerlevel9k.theme" + + # Set default username if not already set! + if [[ -z $(git config user.name) ]]; then + GIT_AUTHOR_NAME_SET_BY_TEST=true + git config --global user.name "${GIT_AUTHOR_NAME}" + fi + # Set default email if not already set! + if [[ -z $(git config user.email) ]]; then + GIT_AUTHOR_EMAIL_SET_BY_TEST=true + git config --global user.email "${GIT_AUTHOR_EMAIL}" + fi + + # Initialize FOLDER as git repository + git init 1>/dev/null +} + +function tearDown() { + if [[ -n "${OLD_GIT_AUTHOR_NAME}" ]]; then + GIT_AUTHOR_NAME=$OLD_GIT_AUTHOR + unset OLD_GIT_AUTHOR_NAME + else + unset GIT_AUTHOR_NAME + fi + + if [[ -n "${OLD_GIT_AUTHOR_EMAIL}" ]]; then + GIT_AUTHOR_EMAIL=$OLD_GIT_AUTHOR_EMAIL + unset OLD_GIT_AUTHOR_EMAIL + else + unset GIT_AUTHOR_EMAIL + fi + + if [[ "${GIT_AUTHOR_NAME_SET_BY_TEST}" == "true" ]]; then + git config --global --unset user.name + fi + if [[ "${GIT_AUTHOR_EMAIL_SET_BY_TEST}" == "true" ]]; then + git config --global --unset user.email + fi + + # Go back to powerlevel9k folder + cd "${P9K_HOME}" + # Remove eventually created test-specific folder + rm -fr "${FOLDER}" + # At least remove test folder completely + rm -fr /tmp/powerlevel9k-test + unset FOLDER +} + +function testColorOverridingForCleanStateWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan' + local POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{006} master %k%F{007}%f " "$(build_left_prompt)" +} + +function testColorOverridingForModifiedStateWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='red' + local POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='yellow' + + touch testfile + git add testfile + git commit -m "test" 1>/dev/null + echo "test" > testfile + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{003} %F{001} master ● %k%F{003}%f " "$(build_left_prompt)" +} + +function testColorOverridingForUntrackedStateWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND='cyan' + local POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND='yellow' + + touch testfile + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{003} %F{006} master ? %k%F{003}%f " "$(build_left_prompt)" +} + +function testGitIconWorks() { + local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_GIT_ICON='Git-Icon' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000}Git-Icon %f%F{000} master %k%F{002}%f " "$(build_left_prompt)" +} + +function testGitlabIconWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_GIT_GITLAB_ICON='GL-Icon' + + # Add a GitLab project as remote origin. This is + # sufficient to show the GitLab-specific icon. + git remote add origin https://gitlab.com/dritter/gitlab-test-project.git + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000}GL-Icon %f%F{000} master %k%F{002}%f " "$(build_left_prompt)" +} + +function testBitbucketIconWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_GIT_BITBUCKET_ICON='BB-Icon' + + # Add a BitBucket project as remote origin. This is + # sufficient to show the BitBucket-specific icon. + git remote add origin https://dritter@bitbucket.org/dritter/dr-test.git + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000}BB-Icon %f%F{000} master %k%F{002}%f " "$(build_left_prompt)" +} + +function testGitHubIconWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_GIT_GITHUB_ICON='GH-Icon' + + # Add a GitHub project as remote origin. This is + # sufficient to show the GitHub-specific icon. + git remote add origin https://github.com/dritter/test.git + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000}GH-Icon %f%F{000} master %k%F{002}%f " "$(build_left_prompt)" +} + +function testUntrackedFilesIconWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_UNTRACKED_ICON='?' + + # Create untracked file + touch "i-am-untracked.txt" + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" +} + +function testStagedFilesIconWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_STAGED_ICON='+' + + # Create staged file + touch "i-am-added.txt" + git add i-am-added.txt &>/dev/null + git commit -m "initial commit" &>/dev/null + echo "xx" >> i-am-added.txt + git add i-am-added.txt &>/dev/null + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{003} %F{000} master + %k%F{003}%f " "$(build_left_prompt)" +} + +function testUnstagedFilesIconWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_UNSTAGED_ICON='M' + + # Create unstaged (modified, but not added to index) file + touch "i-am-modified.txt" + git add i-am-modified.txt + git commit -m "Add File" 1>/dev/null + echo "xx" > i-am-modified.txt + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{003} %F{000} master M %k%F{003}%f " "$(build_left_prompt)" +} + +function testStashIconWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_STASH_ICON='S' + + # Create modified file + touch "i-am-modified.txt" + git add i-am-modified.txt + git commit -m "Add File" 1>/dev/null + echo "xx" > i-am-modified.txt + git stash 1>/dev/null + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} master S1 %k%F{002}%f " "$(build_left_prompt)" +} + +function testTagIconWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_TAG_ICON='T' + + touch "file.txt" + git add file.txt + git commit -m "Add File" 1>/dev/null + git tag "v0.0.1" + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} master Tv0.0.1 %k%F{002}%f " "$(build_left_prompt)" +} + +function testTagIconInDetachedHeadState() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_TAG_ICON='T' + + touch "file.txt" + git add file.txt + git commit -m "Add File" &>/dev/null + git tag "v0.0.1" + touch "file2.txt" + git add file2.txt + git commit -m "Add File2" &>/dev/null + git checkout v0.0.1 &>/dev/null + local hash=$(git rev-list -n 1 --abbrev-commit --abbrev=8 HEAD) + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} ${hash} Tv0.0.1 %k%F{002}%f " "$(build_left_prompt)" +} + +function testActionHintWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + + touch "i-am-modified.txt" + git add i-am-modified.txt + git commit -m "Add File" &>/dev/null + + git clone . ../vcs-test2 &>/dev/null + echo "xx" >> i-am-modified.txt + git commit -a -m "Modified file" &>/dev/null + + cd ../vcs-test2 + echo "yy" >> i-am-modified.txt + git commit -a -m "Provoke conflict" &>/dev/null + git pull &>/dev/null + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{003} %F{000} master %F{red}| merge%f %k%F{003}%f " "$(build_left_prompt)" +} + +function testIncomingHintWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_INCOMING_CHANGES_ICON='I' + + touch "i-am-modified.txt" + git add i-am-modified.txt + git commit -m "Add File" &>/dev/null + + git clone . ../vcs-test2 &>/dev/null + echo "xx" >> i-am-modified.txt + git commit -a -m "Modified file" &>/dev/null + + cd ../vcs-test2 + git fetch &>/dev/null + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} master I1 %k%F{002}%f " "$(build_left_prompt)" +} + +function testOutgoingHintWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_OUTGOING_CHANGES_ICON='o' + + touch "i-am-modified.txt" + git add i-am-modified.txt + git commit -m "Add File" &>/dev/null + + git clone . ../vcs-test2 &>/dev/null + + cd ../vcs-test2 + + echo "xx" >> i-am-modified.txt + git commit -a -m "Modified file" &>/dev/null + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} master o1 %k%F{002}%f " "$(build_left_prompt)" +} + +function testShorteningCommitHashWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_SHOW_CHANGESET=true + local POWERLEVEL9K_CHANGESET_HASH_LENGTH='4' + + touch "file.txt" + git add file.txt + git commit -m "Add File" 1>/dev/null + local hash=$(git rev-list -n 1 --abbrev-commit --abbrev=3 HEAD) + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + # This test needs to call powerlevel9k_vcs_init, where + # the changeset is truncated. + powerlevel9k_vcs_init + assertEquals "%K{002} %F{000}${hash}  master %k%F{002}%f " "$(build_left_prompt)" +} + +function testShorteningCommitHashIsNotShownIfShowChangesetIsFalse() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_SHOW_CHANGESET=false + local POWERLEVEL9K_CHANGESET_HASH_LENGTH='4' + + touch "file.txt" + git add file.txt + git commit -m "Add File" 1>/dev/null + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + # This test needs to call powerlevel9k_vcs_init, where + # the changeset is truncated. + powerlevel9k_vcs_init + assertEquals "%K{002} %F{000} master %k%F{002}%f " "$(build_left_prompt)" +} + +function testDetectingUntrackedFilesInSubmodulesWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true" + unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND + + mkdir ../submodule + cd ../submodule + git init 1>/dev/null + touch "i-am-tracked.txt" + git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null + + local submodulePath="${PWD}" + + cd - + git submodule add "${submodulePath}" 2>/dev/null + git commit -m "Add submodule" 1>/dev/null + + # Go into checked-out submodule path + cd submodule + # Create untracked file + touch "i-am-untracked.txt" + cd - + + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" +} + +function testDetectinUntrackedFilesInMainRepoWithDirtySubmodulesWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true" + unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND + + mkdir ../submodule + cd ../submodule + git init 1>/dev/null + touch "i-am-tracked.txt" + git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null + + local submodulePath="${PWD}" + + cd - + git submodule add "${submodulePath}" 2>/dev/null + git commit -m "Add submodule" 1>/dev/null + + # Create untracked file + touch "i-am-untracked.txt" + + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" +} + +function testDetectingUntrackedFilesInNestedSubmodulesWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true" + unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND + + local mainRepo="${PWD}" + + mkdir ../submodule + cd ../submodule + git init 1>/dev/null + touch "i-am-tracked.txt" + git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null + + local submodulePath="${PWD}" + + mkdir ../subsubmodule + cd ../subsubmodule + git init 1>/dev/null + touch "i-am-tracked-too.txt" + git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null + + local subsubmodulePath="${PWD}" + + cd "${submodulePath}" + git submodule add "${subsubmodulePath}" 2>/dev/null + git commit -m "Add subsubmodule" 1>/dev/null + cd "${mainRepo}" + git submodule add "${submodulePath}" 2>/dev/null + git commit -m "Add submodule" 1>/dev/null + + git submodule update --init --recursive 2>/dev/null + + cd submodule/subsubmodule + # Create untracked file + touch "i-am-untracked.txt" + cd - + + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" +} + +function testDetectingUntrackedFilesInCleanSubdirectoryWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true" + unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND + mkdir clean-folder + touch clean-folder/file.txt + mkdir dirty-folder + touch dirty-folder/file.txt + git add . 2>/dev/null + git commit -m "Initial commit" >/dev/null + touch dirty-folder/new-file.txt + cd clean-folder + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" +} + +source shunit2/shunit2 diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/vcs-hg.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/vcs-hg.spec new file mode 100755 index 0000000..2903f54 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/vcs-hg.spec @@ -0,0 +1,207 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + P9K_HOME=$(pwd) + ### Test specific + # Create default folder and hg init it. + FOLDER=/tmp/powerlevel9k-test/vcs-test + mkdir -p "${FOLDER}" + cd $FOLDER + + export HGUSER="Test bot " + + hg init 1>/dev/null +} + +function tearDown() { + # Go back to powerlevel9k folder + cd "${P9K_HOME}" + # Remove eventually created test-specific folder + rm -fr "${FOLDER}" &>/dev/null + # At least remove test folder completely + rm -fr /tmp/powerlevel9k-test &>/dev/null + unset FOLDER + unset HGUSER +} + +function testColorOverridingForCleanStateWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan' + local POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{007} %F{006} default %k%F{007}%f " "$(build_left_prompt)" +} + +function testColorOverridingForModifiedStateWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='red' + local POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='yellow' + + touch testfile + hg add testfile + hg commit -m "test" 1>/dev/null + echo "test" > testfile + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{003} %F{001} default ● %k%F{003}%f " "$(build_left_prompt)" +} + +# There is no staging area in mercurial, therefore there are no "untracked" +# files.. In case there are added files, we show the VCS segment with a +# yellow background. +# This may be improved in future versions, to be a bit more consistent with +# the git part. +function testAddedFilesIconWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + touch "myfile.txt" + hg add myfile.txt + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{003} %F{000} default ● %k%F{003}%f " "$(build_left_prompt)" +} + +# We don't support tagging in mercurial right now.. +function testTagIconWorks() { + startSkipping # Skip test + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_TAG_ICON='T' + + touch "file.txt" + hg add file.txt + hg commit -m "Add File" 1>/dev/null + hg tag "v0.0.1" + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} default Tv0.0.1 %k%F{002}%f " "$(build_left_prompt)" +} + +function testTagIconInDetachedHeadState() { + startSkipping # Skip test + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_TAG_ICON='T' + + touch "file.txt" + hg add file.txt + hg commit -m "Add File" &>/dev/null + hg tag "v0.0.1" + touch "file2.txt" + hg add file2.txt + hg commit -m "Add File2" &>/dev/null + hg checkout v0.0.1 &>/dev/null + local hash=$(hg id) + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} ${hash} Tv0.0.1 %k%F{002}%f " "$(build_left_prompt)" +} + +function testActionHintWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + touch "i-am-modified.txt" + hg add i-am-modified.txt + hg commit -m "Add File" &>/dev/null + + hg clone . ../vcs-test2 &>/dev/null + echo "xx" >> i-am-modified.txt + hg commit -m "Modified file" &>/dev/null + + cd ../vcs-test2 + echo "yy" >> i-am-modified.txt + hg commit -m "Provoke conflict" 2>/dev/null + hg pull 1>/dev/null + hg merge --tool internal:merge >/dev/null 2>&1 + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{003} %F{000} default %F{red}| merging%f %k%F{003}%f " "$(build_left_prompt)" +} + +function testShorteningCommitHashWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_SHOW_CHANGESET=true + local POWERLEVEL9K_CHANGESET_HASH_LENGTH='4' + + touch "file.txt" + hg add file.txt + hg commit -m "Add File" 1>/dev/null + local hash=$(hg id | head -c ${POWERLEVEL9K_CHANGESET_HASH_LENGTH}) + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + # This test needs to call powerlevel9k_vcs_init, where + # the changeset is truncated. + powerlevel9k_vcs_init + + assertEquals "%K{002} %F{000}${hash}  default %k%F{002}%f " "$(build_left_prompt)" +} + +function testShorteningCommitHashIsNotShownIfShowChangesetIsFalse() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_SHOW_CHANGESET=false + local POWERLEVEL9K_CHANGESET_HASH_LENGTH='4' + + touch "file.txt" + hg add file.txt + hg commit -m "Add File" 1>/dev/null + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + # This test needs to call powerlevel9k_vcs_init, where + # the changeset is truncated. + powerlevel9k_vcs_init + + assertEquals "%K{002} %F{000} default %k%F{002}%f " "$(build_left_prompt)" +} + +function testMercurialIconWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_HG_ICON='HG-Icon' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000}HG-Icon %f%F{000} default %k%F{002}%f " "$(build_left_prompt)" +} + +function testBookmarkIconWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_BOOKMARK_ICON='B' + hg bookmark "initial" + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} default Binitial %k%F{002}%f " "$(build_left_prompt)" +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/vi_mode.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/vi_mode.spec new file mode 100755 index 0000000..6a3a07b --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/segments/vi_mode.spec @@ -0,0 +1,48 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" +} + +function testViInsertModeWorks() { + local KEYMAP='viins' + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{004}INSERT " "$(prompt_vi_mode left 1 false)" +} + +function testViInsertModeWorksWhenLabeledAsMain() { + local KEYMAP='main' + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{004}INSERT " "$(prompt_vi_mode left 1 false)" +} + +function testViCommandModeWorks() { + local KEYMAP='vicmd' + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{007}NORMAL " "$(prompt_vi_mode left 1 false)" +} + +function testViInsertModeStringIsCustomizable() { + local KEYMAP='viins' + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + assertEquals "%K{000} %F{004}INSERT " "$(prompt_vi_mode left 1 false)" +} + +source shunit2/shunit2 \ No newline at end of file diff --git a/config/zsh/oh-my-zsh-custom/powerlevel9k/test/suite.spec b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/suite.spec new file mode 100755 index 0000000..0e51d32 --- /dev/null +++ b/config/zsh/oh-my-zsh-custom/powerlevel9k/test/suite.spec @@ -0,0 +1,17 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +local failed=false + +for test in **/*.spec; do + echo + echo "Now executing ${test}" + if [[ "${test}" == "test/suite.spec" ]]; then + continue; + fi + ./${test} || failed=true +done + +if [[ "${failed}" == "true" ]]; then + exit 1 +fi \ No newline at end of file diff --git a/config/zsh/zsh.nix b/config/zsh/zsh.nix new file mode 100644 index 0000000..2b57e44 --- /dev/null +++ b/config/zsh/zsh.nix @@ -0,0 +1,60 @@ +{pkgs, config, lib, ...}: +{ + programs.zsh = { + enable = true; + dotDir = ".config/zsh"; + enableAutosuggestions = true; + enableCompletion = true; + history = { + expireDuplicatesFirst = true; + ignoreDups = true; + }; + oh-my-zsh = { + enable = true; + custom = "./oh-my-zsh-custom"; + plugins = [ + "git" + "sudo" + ]; + theme = "powerlevel9k/powerlevel9k"; + }; + initExtra = '' + POWERLEVEL9K_MODE='nerdfont-complete' + + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon context dir newline vcs) + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status time) + + POWERLEVEL9K_OS_ICON_BACKGROUND="white" + POWERLEVEL9K_OS_ICON_FOREGROUND="blue" + + POWERLEVEL9K_CONTEXT_DEFAULT_BACKGROUND="green" + POWERLEVEL9K_CONTEXT_DEFAULT_FOREGROUND="white" + POWERLEVEL9K_CONTEXT_SUDO_BACKGROUND="red" + POWERLEVEL9K_CONTEXT_SUDO_FOREGROUND="white" + + POWERLEVEL9K_DIR_HOME_FOREGROUND="white" + POWERLEVEL9K_DIR_HOME_SUBFOLDER_FOREGROUND="white" + POWERLEVEL9K_DIR_DEFAULT_FOREGROUND="white" + POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + POWERLEVEL9K_SHORTEN_DELIMITER=".." + + POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="↱" + POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="↳ " + + + eval "$(ntfy shell-integration)" + AUTO_NTFY_DONE_IGNORE="vim nano screen tmux man" + ''; + }; + + home.file.ntfy = { + source = ./ntfy.yml; + target = ".config/ntfy/ntfy.yml"; + }; + + home.packages = [ + pkgs.nerdfonts + pkgs.ntfy + ]; + +} diff --git a/dunstrc b/dunstrc deleted file mode 100644 index 83afe20..0000000 --- a/dunstrc +++ /dev/null @@ -1,373 +0,0 @@ - [global] - ### Display ### - - # Which monitor should the notifications be displayed on. - monitor = 0 - - # Display notification on focused monitor. Possible modes are: - # mouse: follow mouse pointer - # keyboard: follow window with keyboard focus - # none: don't follow anything - # - # "keyboard" needs a window manager that exports the - # _NET_ACTIVE_WINDOW property. - # This should be the case for almost all modern window managers. - # - # If this option is set to mouse or keyboard, the monitor option - # will be ignored. - follow = mouse - - # The geometry of the window: - # [{width}]x{height}[+/-{x}+/-{y}] - # The geometry of the message window. - # The height is measured in number of notifications everything else - # in pixels. If the width is omitted but the height is given - # ("-geometry x2"), the message window expands over the whole screen - # (dmenu-like). If width is 0, the window expands to the longest - # message displayed. A positive x is measured from the left, a - # negative from the right side of the screen. Y is measured from - # the top and down respectively. - # The width can be negative. In this case the actual width is the - # screen width minus the width defined in within the geometry option. - geometry = "300x5-30+20" - - # Show how many messages are currently hidden (because of geometry). - indicate_hidden = yes - - # Shrink window if it's smaller than the width. Will be ignored if - # width is 0. - shrink = no - - # The transparency of the window. Range: [0; 100]. - # This option will only work if a compositing window manager is - # present (e.g. xcompmgr, compiz, etc.). - transparency = 0 - - # The height of the entire notification. If the height is smaller - # than the font height and padding combined, it will be raised - # to the font height and padding. - notification_height = 0 - - # Draw a line of "separator_height" pixel height between two - # notifications. - # Set to 0 to disable. - separator_height = 2 - - # Padding between text and separator. - padding = 8 - - # Horizontal padding. - horizontal_padding = 8 - - # Defines width in pixels of frame around the notification window. - # Set to 0 to disable. - frame_width = 3 - - # Defines color of the frame around the notification window. - frame_color = "#aaaaaa" - - # Define a color for the separator. - # possible values are: - # * auto: dunst tries to find a color fitting to the background; - # * foreground: use the same color as the foreground; - # * frame: use the same color as the frame; - # * anything else will be interpreted as a X color. - separator_color = frame - - # Sort messages by urgency. - sort = yes - - # Don't remove messages, if the user is idle (no mouse or keyboard input) - # for longer than idle_threshold seconds. - # Set to 0 to disable. - # Transient notifications ignore this setting. - idle_threshold = 120 - - ### Text ### - - font = Monospace 8 - - # The spacing between lines. If the height is smaller than the - # font height, it will get raised to the font height. - line_height = 0 - - # Possible values are: - # full: Allow a small subset of html markup in notifications: - # bold - # italic - # strikethrough - # underline - # - # For a complete reference see - # . - # - # strip: This setting is provided for compatibility with some broken - # clients that send markup even though it's not enabled on the - # server. Dunst will try to strip the markup but the parsing is - # simplistic so using this option outside of matching rules for - # specific applications *IS GREATLY DISCOURAGED*. - # - # no: Disable markup parsing, incoming notifications will be treated as - # plain text. Dunst will not advertise that it has the body-markup - # capability if this is set as a global setting. - # - # It's important to note that markup inside the format option will be parsed - # regardless of what this is set to. - markup = full - - # The format of the message. Possible variables are: - # %a appname - # %s summary - # %b body - # %i iconname (including its path) - # %I iconname (without its path) - # %p progress value if set ([ 0%] to [100%]) or nothing - # %n progress value if set without any extra characters - # %% Literal % - # Markup is allowed - format = "%s\n%b" - - # Alignment of message text. - # Possible values are "left", "center" and "right". - alignment = left - - # Show age of message if message is older than show_age_threshold - # seconds. - # Set to -1 to disable. - show_age_threshold = 60 - - # Split notifications into multiple lines if they don't fit into - # geometry. - word_wrap = yes - - # When word_wrap is set to no, specify where to make an ellipsis in long lines. - # Possible values are "start", "middle" and "end". - ellipsize = middle - - # Ignore newlines '\n' in notifications. - ignore_newline = no - - # Stack together notifications with the same content - stack_duplicates = true - - # Hide the count of stacked notifications with the same content - hide_duplicate_count = false - - # Display indicators for URLs (U) and actions (A). - show_indicators = yes - - ### Icons ### - - # Align icons left/right/off - icon_position = off - - # Scale larger icons down to this size, set to 0 to disable - max_icon_size = 32 - - # Paths to default icons. - icon_path = /usr/share/icons/gnome/16x16/status/:/usr/share/icons/gnome/16x16/devices/ - - ### History ### - - # Should a notification popped up from history be sticky or timeout - # as if it would normally do. - sticky_history = yes - - # Maximum amount of notifications kept in history - history_length = 20 - - ### Misc/Advanced ### - - # dmenu path. - dmenu = /usr/bin/dmenu -p dunst: - - # Browser for opening urls in context menu. - browser = /usr/bin/firefox -new-tab - - # Always run rule-defined scripts, even if the notification is suppressed - always_run_script = true - - # Define the title of the windows spawned by dunst - title = Dunst - - # Define the class of the windows spawned by dunst - class = Dunst - - # Print a notification on startup. - # This is mainly for error detection, since dbus (re-)starts dunst - # automatically after a crash. - startup_notification = false - - # Manage dunst's desire for talking - # Can be one of the following values: - # crit: Critical features. Dunst aborts - # warn: Only non-fatal warnings - # mesg: Important Messages - # info: all unimportant stuff - # debug: all less than unimportant stuff - verbosity = mesg - - # Define the corner radius of the notification window - # in pixel size. If the radius is 0, you have no rounded - # corners. - # The radius will be automatically lowered if it exceeds half of the - # notification height to avoid clipping text and/or icons. - corner_radius = 0 - - ### Legacy - - # Use the Xinerama extension instead of RandR for multi-monitor support. - # This setting is provided for compatibility with older nVidia drivers that - # do not support RandR and using it on systems that support RandR is highly - # discouraged. - # - # By enabling this setting dunst will not be able to detect when a monitor - # is connected or disconnected which might break follow mode if the screen - # layout changes. - force_xinerama = false - - ### mouse - - # Defines action of mouse event - # Possible values are: - # * none: Don't do anything. - # * do_action: If the notification has exactly one action, or one is marked as default, - # invoke it. If there are multiple and no default, open the context menu. - # * close_current: Close current notification. - # * close_all: Close all notifications. - mouse_left_click = close_current - mouse_middle_click = do_action - mouse_right_click = close_all - -# Experimental features that may or may not work correctly. Do not expect them -# to have a consistent behaviour across releases. -[experimental] - # Calculate the dpi to use on a per-monitor basis. - # If this setting is enabled the Xft.dpi value will be ignored and instead - # dunst will attempt to calculate an appropriate dpi value for each monitor - # using the resolution and physical size. This might be useful in setups - # where there are multiple screens with very different dpi values. - per_monitor_dpi = false - -[shortcuts] - - # Shortcuts are specified as [modifier+][modifier+]...key - # Available modifiers are "ctrl", "mod1" (the alt-key), "mod2", - # "mod3" and "mod4" (windows-key). - # Xev might be helpful to find names for keys. - - # Close notification. - close = mod4+space - - # Close all notifications. - #close_all = ctrl+shift+space - - # Redisplay last message(s). - # On the US keyboard layout "grave" is normally above TAB and left - # of "1". Make sure this key actually exists on your keyboard layout, - # e.g. check output of 'xmodmap -pke' - history = mod4+bar - - # Context menu. - #context = ctrl+shift+period - -[urgency_low] - # IMPORTANT: colors have to be defined in quotation marks. - # Otherwise the "#" and following would be interpreted as a comment. - background = "#222222" - foreground = "#888888" - timeout = 10 - # Icon for notifications with low urgency, uncomment to enable - #icon = /path/to/icon - -[urgency_normal] - background = "#285577" - foreground = "#ffffff" - timeout = 10 - # Icon for notifications with normal urgency, uncomment to enable - #icon = /path/to/icon - -[urgency_critical] - background = "#900000" - foreground = "#ffffff" - frame_color = "#ff0000" - timeout = 0 - # Icon for notifications with critical urgency, uncomment to enable - #icon = /path/to/icon - -# Every section that isn't one of the above is interpreted as a rules to -# override settings for certain messages. -# Messages can be matched by "appname", "summary", "body", "icon", "category", -# "msg_urgency" and you can override the "timeout", "urgency", "foreground", -# "background", "frame_color", "new_icon" and "format", "fullscreen", -# "stack_tag". -# Shell-like globbing will get expanded. -# -# SCRIPTING -# You can specify a script that gets run when the rule matches by -# setting the "script" option. -# The script will be called as follows: -# script appname summary body icon urgency -# where urgency can be "LOW", "NORMAL" or "CRITICAL". -# -# NOTE: if you don't want a notification to be displayed, set the format -# to "". -# NOTE: It might be helpful to run dunst -print in a terminal in order -# to find fitting options for rules. - -# fullscreen values -# show: show the notifications, regardless if there is a fullscreen window opened -# delay: displays the new notification, if there is no fullscreen window active -# If the notification is already drawn, it won't get undrawn. -# pushback: same as delay, but when switching into fullscreen, the notification will get -# withdrawn from screen again and will get delayed like a new notification - -#[fullscreen_delay_everything] -# fullscreen = delay -#[fullscreen_show_critical] -# msg_urgency = critical -# fullscreen = show - -#[espeak] -# summary = "*" -# script = dunst_espeak.sh - -#[script-test] -# summary = "*script*" -# script = dunst_test.sh - -#[ignore] -# # This notification will not be displayed -# summary = "foobar" -# format = "" - -#[history-ignore] -# # This notification will not be saved in history -# summary = "foobar" -# history_ignore = yes - -#[signed_on] -# appname = Pidgin -# summary = "*signed on*" -# urgency = low -# -#[signed_off] -# appname = Pidgin -# summary = *signed off* -# urgency = low -# -#[says] -# appname = Pidgin -# summary = *says* -# urgency = critical -# -#[twitter] -# appname = Pidgin -# summary = *twitter.com* -# urgency = normal -# -#[stack-volumes] -# appname = "some_volume_notifiers" -# set_stack_tag = "volume" -# -# vim: ft=cfg diff --git a/home.nix b/home.nix index c8516c1..5e4093c 100644 --- a/home.nix +++ b/home.nix @@ -7,53 +7,7 @@ # target = ".config/nixpkgs/overlays"; #}; - home.keyboard = { - layout = "no-latin1"; - }; - - xsession = { - enable = true; - windowManager = { - i3.enable = true; - i3.config = { - modifier = "Mod4"; - keybindings = let modifier = "Mod4"; #xsession.windowManager.i3.config.modifier; - in lib.mkOptionDefault { - "${modifier}+0" = "workspace 10"; - "${modifier}+Shift+0" = "move container to workspace 10"; - - "${modifier}+Tab" = "workspace next"; - "${modifier}+Shift+Tab" = "workspace prev"; - - "XF86AudioRaiseVolume" = "exec --no-startup-id pactl set-sink-volume 0 +5%"; - "XF86AudioLowerVolume" = "exec --no-startup-id pactl set-sink-volume 0 -5%"; - "XF86AudioMute" = "exec --no-startup-id pactl set-sink-mute 0 toggle"; - "XF86AudioMicMute" = "exec --no-startup-id pactl set-source-mute 1 toggle"; - - "XF86MonBrightnessUp" = "exec --no-startup-id xbacklight -inc 5"; - "XF86MonBrightnessDown" = "exec --no-startup-id xbacklight -dec 5"; - - "XF86Display" = "exec arandr"; - - "Print" = "exec scrot %Y-%m-%d_$wx$h_scrot.png -z -e 'mv $f /home/daniel/Pictures/screenshots/'"; - "${modifier}+Print" = "exec scrot %Y-%m-%d_$wx$h_scrot.png -z -e 'mv $f /home/daniel/Pictures/screenshots/'"; - - - "${modifier}+n" = "exec dolphin"; - "${modifier}+b" = "exec firefox"; - "${modifier}+t" = "exec gedit"; - - "${modifier}+Return" = lib.mkForce "exec i3-sensible-terminal -e zsh"; - "${modifier}+Shift+Return" = "exec i3-sensible-terminal -e ssh daniel@adam"; - }; - }; - }; - }; - - services.compton = { - enable = true; - backend = "xrender"; - }; + imports = [ ./config/xsession.nix ./config/zsh/zsh.nix ./config/dunstrc.nix ]; programs.urxvt = { enable = true; @@ -85,69 +39,10 @@ }; }; - programs.zsh = { - enable = true; - dotDir = ".config/zsh"; - enableAutosuggestions = true; - enableCompletion = true; - history = { - expireDuplicatesFirst = true; - ignoreDups = true; - }; - oh-my-zsh = { - enable = true; - custom = "\$HOME/.config/nixpkgs/nix-dotfiles/zsh/oh-my-zsh-custom"; - plugins = [ - "git" - "sudo" - ]; - theme = "powerlevel9k/powerlevel9k"; - }; - initExtra = '' - POWERLEVEL9K_MODE='nerdfont-complete' - - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon context dir newline vcs) - POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status time) - - POWERLEVEL9K_OS_ICON_BACKGROUND="white" - POWERLEVEL9K_OS_ICON_FOREGROUND="blue" - - POWERLEVEL9K_CONTEXT_DEFAULT_BACKGROUND="green" - POWERLEVEL9K_CONTEXT_DEFAULT_FOREGROUND="white" - POWERLEVEL9K_CONTEXT_SUDO_BACKGROUND="red" - POWERLEVEL9K_CONTEXT_SUDO_FOREGROUND="white" - - POWERLEVEL9K_DIR_HOME_FOREGROUND="white" - POWERLEVEL9K_DIR_HOME_SUBFOLDER_FOREGROUND="white" - POWERLEVEL9K_DIR_DEFAULT_FOREGROUND="white" - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_DELIMITER=".." - - POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="↱" - POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="↳ " - - - eval "$(ntfy shell-integration)" - AUTO_NTFY_DONE_IGNORE="vim nano screen tmux man" - ''; - }; - - home.file.ntfy = { - source = ./secret/ntfy.yml; - target = ".config/ntfy/ntfy.yml"; - }; - - home.file.dunst = { - source = ./dunstrc; - target = ".config/dunst/dunstrc"; - }; - programs.direnv = { enable = true; }; - services.nextcloud-client.enable = true; - home.packages = [ pkgs.gnome3.gnome-terminal @@ -156,10 +51,8 @@ pkgs.libguestfs pkgs.virtmanager - pkgs.nerdfonts pkgs.dejavu_fonts - pkgs.ntfy - pkgs.dunst + pkgs.scrot pkgs.xorg.xbacklight diff --git a/ntfy.yml.example b/ntfy.yml.example deleted file mode 100644 index e528958..0000000 --- a/ntfy.yml.example +++ /dev/null @@ -1,7 +0,0 @@ ---- -backends: - - matrix -matrix: - url: "https://matrix.dodsorf.as" - roomId: "***REMOVED***" - token: "AAAbbBBCC" diff --git a/zsh/oh-my-zsh-custom/powerlevel9k b/zsh/oh-my-zsh-custom/powerlevel9k deleted file mode 160000 index c7d8ef0..0000000 --- a/zsh/oh-my-zsh-custom/powerlevel9k +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c7d8ef07b76b9dc6022c656c761b6422ce919e94