2017-11-15 14:37:19 +00:00
|
|
|
####################################
|
|
|
|
# Jessie Hildebrandt's Fish Config #
|
|
|
|
####################################
|
|
|
|
|
2019-10-29 21:56:33 +00:00
|
|
|
# Contains a pretty multi-line prompt and some useful functions.
|
|
|
|
# Compatible with Emacs' ansi-term.
|
|
|
|
#
|
|
|
|
# Provided functions:
|
|
|
|
# * battery - Displays the battery charge (and discharge time if supported)
|
|
|
|
#
|
|
|
|
# Prompt features:
|
|
|
|
# * SSH session indicator
|
|
|
|
# * Virtual environment indicator
|
|
|
|
# * Abbreviated + colorized working directory
|
|
|
|
# * VCS status
|
|
|
|
# * Dynamic prompt character (root/user, return status)
|
2019-11-04 10:24:12 +00:00
|
|
|
# * Dynamic greeting function
|
2019-10-29 21:56:33 +00:00
|
|
|
# * Optional timestamps
|
2021-03-29 18:28:04 +00:00
|
|
|
# * Automatic aliasing of 'rm' -> 'rm -i' for root sessions
|
2019-10-29 21:56:33 +00:00
|
|
|
#
|
|
|
|
# Configurable variables:
|
|
|
|
# * __fish_prompt_show_timestamps - If set, displays timestamps on the right side of the terminal
|
2019-11-04 09:16:36 +00:00
|
|
|
# * __fish_greeting_fortune_cookies - Overrides the default list of fortune cookies to use for greetings
|
2021-03-29 18:28:04 +00:00
|
|
|
# * __fish_disable_interactive_root_rm - If set, disables automatic aliasing of 'rm' to 'rm -i' when signed in as root
|
2019-10-29 21:56:33 +00:00
|
|
|
|
2022-12-12 06:17:30 +00:00
|
|
|
################
|
|
|
|
# Color Config #
|
|
|
|
################
|
|
|
|
|
|
|
|
set fish_color_command ffa348
|
|
|
|
set fish_color_quote 5bc8af
|
|
|
|
set fish_color_comment 656565
|
|
|
|
set fish_color_autosuggestion 656565
|
|
|
|
set fish_color_param normal
|
|
|
|
set fish_color_operator 7d8ac7
|
|
|
|
set fish_color_escape 7d8ac7
|
|
|
|
set fish_color_error ff6c6b
|
|
|
|
|
|
|
|
set -x LS_COLORS "no=00:fi=00:di=01;94:ln=01;96:or=41;96;01:ex=92:mi=90:pi=35:so=35:bd=33:cd=33:"
|
|
|
|
|
2023-02-15 20:40:22 +00:00
|
|
|
####################
|
|
|
|
# VC Status Glyphs #
|
|
|
|
####################
|
|
|
|
|
|
|
|
set ___fish_git_prompt_char_cleanstate ✓
|
|
|
|
set ___fish_git_prompt_char_dirtystate +
|
|
|
|
set ___fish_git_prompt_char_invalidstate x
|
2023-02-15 21:32:35 +00:00
|
|
|
set ___fish_git_prompt_char_stagedstate →
|
2023-02-15 20:40:22 +00:00
|
|
|
set ___fish_git_prompt_char_stashstate ↳
|
|
|
|
set ___fish_git_prompt_char_untrackedfiles …
|
|
|
|
set ___fish_git_prompt_char_upstream_ahead ↑
|
|
|
|
set ___fish_git_prompt_char_upstream_behind ↓
|
|
|
|
set ___fish_git_prompt_char_upstream_diverged ⟷
|
|
|
|
set ___fish_git_prompt_char_upstream_equal =
|
|
|
|
|
|
|
|
set fish_prompt_hg_status_added +
|
|
|
|
set fish_prompt_hg_status_copied ↳
|
|
|
|
set fish_prompt_hg_status_deleted x
|
|
|
|
set fish_prompt_hg_status_modified +
|
|
|
|
set fish_prompt_hg_status_unmerged ⟷
|
|
|
|
set fish_prompt_hg_status_untracked …
|
|
|
|
|
2017-11-15 14:37:19 +00:00
|
|
|
#####################
|
|
|
|
# Setting Variables #
|
|
|
|
#####################
|
|
|
|
|
2019-10-29 07:30:07 +00:00
|
|
|
set __fish_git_prompt_show_informative_status true
|
2017-11-15 14:37:19 +00:00
|
|
|
|
|
|
|
set fish_key_bindings fish_default_key_bindings
|
|
|
|
|
2019-10-29 07:30:07 +00:00
|
|
|
set VIRTUAL_ENV_DISABLE_PROMPT true
|
|
|
|
|
2023-02-15 21:32:47 +00:00
|
|
|
# Add '~/.local/bin' using 'fish_add_path' (Only available in Fish 3.2.X and above)
|
|
|
|
if type fish_add_path &> /dev/null
|
2024-04-12 03:46:15 +00:00
|
|
|
fish_add_path -P ~/.local/bin
|
2023-02-15 21:32:47 +00:00
|
|
|
end
|
2022-02-03 06:11:06 +00:00
|
|
|
|
2021-03-29 18:28:04 +00:00
|
|
|
###########
|
|
|
|
# Aliases #
|
|
|
|
###########
|
|
|
|
|
|
|
|
# Conditionally set 'rm' -> 'rm -i' alias for the root user only
|
|
|
|
switch (id -u)
|
|
|
|
case 0
|
|
|
|
# Root
|
|
|
|
if not set -q __fish_disable_interactive_root_rm
|
|
|
|
alias rm 'rm -i'
|
|
|
|
end
|
|
|
|
case '*'
|
|
|
|
# Everyone else
|
|
|
|
end
|
|
|
|
|
2023-02-26 17:09:08 +00:00
|
|
|
# Useful aliases
|
2023-02-15 20:40:22 +00:00
|
|
|
alias lsl 'ls -lh'
|
2023-03-10 19:57:34 +00:00
|
|
|
alias history-clear-sensitive 'history delete --contains token --contains pass --contains auth --contains key --contains login --contains secret'
|
2023-02-26 17:09:08 +00:00
|
|
|
alias addtopath 'fish_add_path -P'
|
2023-02-15 20:40:22 +00:00
|
|
|
|
2019-11-04 09:16:36 +00:00
|
|
|
#####################
|
|
|
|
# Greeting Function #
|
|
|
|
#####################
|
|
|
|
|
|
|
|
function fish_greeting --description 'Display a greeting when the session begins'
|
|
|
|
|
|
|
|
##################
|
|
|
|
# Fortune greeting
|
|
|
|
|
|
|
|
if type -q fortune
|
|
|
|
|
|
|
|
# Set up list of desired cookies
|
|
|
|
set -l desired_cookies
|
|
|
|
if not set -q __fish_greeting_fortune_cookies
|
|
|
|
set desired_cookies computers people science education work wisdom
|
|
|
|
else
|
|
|
|
set desired_cookies $__fish_greeting_fortune_cookies
|
|
|
|
end
|
|
|
|
|
|
|
|
# Determine which desired cookies are available
|
|
|
|
set -l found_cookies
|
|
|
|
for cookie in $desired_cookies
|
2021-09-08 12:30:23 +00:00
|
|
|
if fortune -s $cookie &> /dev/null
|
2019-11-04 09:16:36 +00:00
|
|
|
set -a found_cookies $cookie
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# If any desired cookies are found, source a fortune from them
|
|
|
|
if test (count $found_cookies) -gt 0
|
|
|
|
fortune -s $found_cookies
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# Otherwise, just print whatever
|
|
|
|
fortune -s
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
#################
|
|
|
|
# Static greeting
|
|
|
|
|
|
|
|
echo "Hello, commander."
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2019-10-29 21:55:03 +00:00
|
|
|
####################
|
|
|
|
# Battery Function #
|
|
|
|
####################
|
|
|
|
|
|
|
|
function battery --description 'Display the current status of the battery'
|
|
|
|
|
|
|
|
#################
|
|
|
|
# Local variables
|
|
|
|
|
2019-11-04 09:16:36 +00:00
|
|
|
set -l battery_files /sys/class/power_supply/BAT*/capacity
|
2019-10-29 21:55:03 +00:00
|
|
|
|
|
|
|
set -l normal (set_color normal)
|
|
|
|
set -l yellow (set_color bryellow)
|
2019-11-04 09:16:36 +00:00
|
|
|
set -l gray (set_color 5e5e5e brblack)
|
2019-10-29 21:55:03 +00:00
|
|
|
|
|
|
|
#####################
|
|
|
|
# ACPI battery status
|
|
|
|
|
2019-11-04 10:24:12 +00:00
|
|
|
if type -q acpi
|
2019-11-04 09:16:36 +00:00
|
|
|
set -l battery_str (acpi | grep "Unknown" --invert | head -n 1 | cut -d "," -f 2- | string trim)
|
2019-11-04 10:32:06 +00:00
|
|
|
set battery_str (string replace -r '([[:digit:]]{1,3}%),? ?(.*)$' "$yellow\$1$normal $gray(\$2)$normal" $battery_str)
|
|
|
|
set battery_str (string replace -r '\(\)' "(Fully charged)" $battery_str)
|
2019-11-04 09:16:36 +00:00
|
|
|
echo "Battery status: $battery_str"
|
2019-10-29 21:55:03 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
#########################
|
|
|
|
# Fallback battery status
|
|
|
|
|
2019-11-04 09:16:36 +00:00
|
|
|
if test -f $battery_files
|
2019-11-04 10:24:12 +00:00
|
|
|
set -l battery_str (cat $battery_files | head -n 1 | string trim)
|
|
|
|
set battery_str (string replace -r '([[:digit:]]{1,3})' "$yellow\$1%$normal" $battery_str)
|
2019-11-04 09:16:36 +00:00
|
|
|
echo "Battery status: $battery_str"
|
2019-10-29 21:55:03 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
#####################
|
|
|
|
# Unsupported battery
|
|
|
|
|
2019-11-04 09:16:36 +00:00
|
|
|
echo "No battery detected."
|
2019-10-29 21:55:03 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2019-10-29 00:12:52 +00:00
|
|
|
##################
|
|
|
|
# Title Function #
|
|
|
|
##################
|
|
|
|
|
|
|
|
function fish_title --description 'Print the title of the window'
|
|
|
|
|
2019-10-29 07:30:07 +00:00
|
|
|
# Trying to set the title inside of Emacs will break it
|
2019-10-29 00:12:52 +00:00
|
|
|
if set -q INSIDE_EMACS
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-11-04 10:24:12 +00:00
|
|
|
# Set window title to the current command + working directory
|
|
|
|
if test (echo $FISH_VERSION | cut -d "." -f 1) -ge 3
|
|
|
|
|
|
|
|
# Fish 3.X.X and above use "status current-command"
|
2023-02-15 21:51:53 +00:00
|
|
|
echo (status current-command) (prompt_pwd)
|
2019-11-04 10:24:12 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
# Older versions of fish use the "$_" variable
|
2023-02-15 21:51:53 +00:00
|
|
|
echo $_ (prompt_pwd)
|
2019-11-04 10:24:12 +00:00
|
|
|
|
|
|
|
end
|
2019-10-29 00:12:52 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2017-11-15 14:37:19 +00:00
|
|
|
###################
|
|
|
|
# Prompt Function #
|
|
|
|
###################
|
|
|
|
|
2019-11-04 09:16:36 +00:00
|
|
|
function fish_prompt --description 'Display a formatted terminal prompt'
|
2017-11-15 14:37:19 +00:00
|
|
|
|
2019-10-29 07:30:07 +00:00
|
|
|
####################
|
|
|
|
# Exit Status
|
|
|
|
|
|
|
|
# Cache the exit status of the last command
|
2018-05-05 02:08:29 +00:00
|
|
|
set -l last_status $status
|
|
|
|
|
2019-10-29 07:30:07 +00:00
|
|
|
##################
|
|
|
|
# Global Variables
|
|
|
|
|
|
|
|
# Format host name variable if not yet set
|
|
|
|
if not set -q __fish_prompt_hostname
|
|
|
|
set -g __fish_prompt_hostname (prompt_hostname)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Format prompt character variable if not yet set
|
|
|
|
if not set -q __fish_prompt_char
|
|
|
|
switch (id -u)
|
|
|
|
case 0
|
|
|
|
# Root
|
2023-02-15 21:33:07 +00:00
|
|
|
set -g __fish_prompt_char "⌦"
|
2019-10-29 07:30:07 +00:00
|
|
|
case '*'
|
|
|
|
# Everyone else
|
2023-02-15 21:33:07 +00:00
|
|
|
set -g __fish_prompt_char "❱"
|
2019-10-29 07:30:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
#################
|
|
|
|
# Local Variables
|
|
|
|
|
|
|
|
set -l normal (set_color normal)
|
|
|
|
set -l white (set_color brwhite)
|
2022-12-12 06:17:30 +00:00
|
|
|
set -l gray (set_color 7b7b7b brblack)
|
|
|
|
set -l darkgray (set_color 454545 brblack)
|
|
|
|
set -l cyan (set_color 7ee5ff brblue)
|
|
|
|
set -l teal (set_color 5bc8af brgreen)
|
|
|
|
set -l red (set_color ff6c6b brred)
|
2019-10-29 07:30:07 +00:00
|
|
|
|
|
|
|
#############
|
|
|
|
# SSH Segment
|
2018-05-05 02:08:29 +00:00
|
|
|
|
2019-10-29 07:30:07 +00:00
|
|
|
set -l ssh_seg ""
|
2018-05-05 02:25:53 +00:00
|
|
|
if test -n "$SSH_CONNECTION"
|
2023-02-15 21:57:44 +00:00
|
|
|
set ssh_seg "$white" "remote" "$normal: "
|
2018-05-05 02:25:53 +00:00
|
|
|
end
|
|
|
|
|
2019-10-29 07:30:07 +00:00
|
|
|
#############################
|
|
|
|
# Virtual Environment Segment
|
|
|
|
|
|
|
|
set -l venv_seg ""
|
|
|
|
if test -n "$VIRTUAL_ENV"
|
2019-11-04 09:16:36 +00:00
|
|
|
set venv_seg "$gray("(basename $VIRTUAL_ENV)")$normal "
|
2019-10-29 07:30:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#################
|
|
|
|
# User@Host Segment
|
2018-05-05 02:08:29 +00:00
|
|
|
|
2022-12-12 06:17:30 +00:00
|
|
|
set -l user_host_seg "$cyan$USER$normal at $teal$__fish_prompt_hostname$normal "
|
2018-05-05 02:08:29 +00:00
|
|
|
|
2019-10-29 07:30:07 +00:00
|
|
|
###########################
|
|
|
|
# Working Directory (PWD) Segment
|
2018-05-05 02:08:29 +00:00
|
|
|
|
2019-10-29 07:30:07 +00:00
|
|
|
set -g fish_prompt_pwd_dir_length 1
|
2019-11-04 09:16:36 +00:00
|
|
|
set -l pwd_seg (prompt_pwd)
|
|
|
|
if test (string length $pwd_seg) -eq 1
|
|
|
|
set pwd_seg (string replace -ar '^.*$' "in $gray\$0$normal" $pwd_seg)
|
|
|
|
else
|
|
|
|
set pwd_seg (string replace -ar '^(.*[~\/])([^\/]*$)' "in $darkgray\$1$gray\$2$normal" $pwd_seg)
|
|
|
|
end
|
2018-05-05 02:08:29 +00:00
|
|
|
|
2019-10-29 07:30:07 +00:00
|
|
|
####################
|
|
|
|
# VCS Status Segment
|
|
|
|
|
2023-02-15 21:33:14 +00:00
|
|
|
set -l vcs_seg (string replace -r "^ \(" " 「" (string replace -r "\)\$" "」" (__fish_vcs_prompt)))
|
2019-10-29 07:30:07 +00:00
|
|
|
|
|
|
|
##################
|
|
|
|
# Prompt Character
|
|
|
|
|
|
|
|
set -l prompt_char "$cyan$__fish_prompt_char$normal "
|
2018-05-05 02:08:29 +00:00
|
|
|
if test $last_status -ne 0
|
2019-10-29 07:30:07 +00:00
|
|
|
set prompt_char "$red$__fish_prompt_char$normal "
|
2018-05-05 02:08:29 +00:00
|
|
|
end
|
|
|
|
|
2019-10-29 07:30:07 +00:00
|
|
|
#########
|
|
|
|
# Output
|
|
|
|
|
2019-11-04 09:29:09 +00:00
|
|
|
echo -se "\n" $venv_seg $ssh_seg $user_host_seg $pwd_seg $vcs_seg "\n" $prompt_char
|
2017-11-15 14:37:19 +00:00
|
|
|
|
2018-02-04 07:26:27 +00:00
|
|
|
end
|
2019-10-29 21:55:55 +00:00
|
|
|
|
|
|
|
#########################
|
|
|
|
# Right Prompt Function #
|
|
|
|
#########################
|
|
|
|
|
2019-11-04 09:16:36 +00:00
|
|
|
function fish_right_prompt --description "Display a right-aligned terminal prompt"
|
2019-10-29 21:55:55 +00:00
|
|
|
|
|
|
|
#############################
|
|
|
|
# Enable/disable right prompt
|
|
|
|
|
|
|
|
if not set -q __fish_prompt_show_timestamps
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
#################
|
|
|
|
# Local variables
|
|
|
|
|
2019-11-04 09:16:36 +00:00
|
|
|
set -l normal (set_color normal)
|
2019-10-29 21:55:55 +00:00
|
|
|
set -l darkgray (set_color 3b3b3b brblack)
|
|
|
|
|
|
|
|
###########
|
|
|
|
# Timestamp
|
|
|
|
|
2019-11-04 09:16:36 +00:00
|
|
|
set -l timestamp_str "$darkgray"(date +"[%H:%M:%S]")"$normal"
|
|
|
|
echo -s "$darkgray$timestamp_str"
|
2019-10-29 21:55:55 +00:00
|
|
|
|
|
|
|
end
|