mirror of
				https://github.com/ItsDrike/dotfiles.git
				synced 2025-11-04 01:16:35 +00:00 
			
		
		
		
	Merge branch 'arch' into gentoo
This commit is contained in:
		
						commit
						8b8f5f40c6
					
				
					 4 changed files with 121 additions and 9 deletions
				
			
		| 
						 | 
				
			
			@ -1,5 +1,28 @@
 | 
			
		|||
#!/usr/bin/env zsh
 | 
			
		||||
 | 
			
		||||
# Configuration variables:
 | 
			
		||||
 | 
			
		||||
# Once we are too deep in the filestructure, we can usually afford to shorten
 | 
			
		||||
# the whole working directory and only print something like ~/.../dir3/dir4/dir5
 | 
			
		||||
# instead of ~/dir1/dir2/dir3/dir4/dir5. If this isn't desired, set this to 0
 | 
			
		||||
USE_SHORTENED_WORKDIR=1
 | 
			
		||||
 | 
			
		||||
# Show how much time it took to run a command
 | 
			
		||||
CMD_TIME_SHOW=1
 | 
			
		||||
# Minimum units to show the time precision, if
 | 
			
		||||
# we use "s" (seconds), and the output took 0s,
 | 
			
		||||
# we don't print the output at all to avoid clutter.
 | 
			
		||||
# Same goes for any other units, however with "ms"
 | 
			
		||||
# (miliseconds), this is very unlikely
 | 
			
		||||
# Valid options: ms/s/m/h/d
 | 
			
		||||
CMD_TIME_PRECISION="s"
 | 
			
		||||
# Minimum time in miliseconds, to print the time took,
 | 
			
		||||
# if the command takes less than this amount of miliseconds,
 | 
			
		||||
# don't bother printing the time took, this is nice if you
 | 
			
		||||
# don't need to see how long commands like 'echo' took
 | 
			
		||||
# Setting this to 0 will always print the time taken
 | 
			
		||||
CMD_TIME_MINIMUM=100
 | 
			
		||||
 | 
			
		||||
# hide EOL sign ('%')
 | 
			
		||||
export PROMPT_EOL_MARK=""
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -24,11 +47,6 @@ else
 | 
			
		|||
fi
 | 
			
		||||
RESET="%f"
 | 
			
		||||
 | 
			
		||||
# Once we are too deep in the filestructure, we can usually afford to shorten
 | 
			
		||||
# the whole working directory and only print something like ~/.../dir3/dir4/dir5
 | 
			
		||||
# instead of ~/dir1/dir2/dir3/dir4/dir5. If this isn't desired, set this to 0
 | 
			
		||||
USE_SHORTENED_WORKDIR=1
 | 
			
		||||
 | 
			
		||||
# Signals git status of CWD repository (if any)
 | 
			
		||||
git_prompt() {
 | 
			
		||||
    ref=$(command git symbolic-ref HEAD 2> /dev/null) || ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
 | 
			
		||||
| 
						 | 
				
			
			@ -64,22 +82,97 @@ working_directory() {
 | 
			
		|||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Execution time tracking hooks, this is unique to zsh, as it can add
 | 
			
		||||
# preexec and precmd hooks. We can utilize this to keep track of the
 | 
			
		||||
# amount of time it took to run certain command. We store the start time
 | 
			
		||||
# within a variable: PROMPT_EXEC_TIME_START, which we then compare and
 | 
			
		||||
# unset after the command was finished. In here, we simply set the
 | 
			
		||||
# PROMPT_EXEC_TIME_DURATION, which is then used in the actual prompt
 | 
			
		||||
# This will only be enabled if SHOW_CMD_TIME is 1.
 | 
			
		||||
exec_time_preexec_hook() {
 | 
			
		||||
    [[ $SHOW_CMD_TIME == 0 ]] && return
 | 
			
		||||
    PROMPT_EXEC_TIME_START=$(date +%s.%N)
 | 
			
		||||
}
 | 
			
		||||
exec_time_precmd_hook() {
 | 
			
		||||
    [[ $SHOW_CMD_TIME == 0 ]] && return
 | 
			
		||||
    [[ -z $PROMPT_EXEC_TIME_START ]] && return
 | 
			
		||||
    local PROMPT_EXEC_TIME_STOP=$(date +%s.%N)
 | 
			
		||||
    PROMPT_EXEC_TIME_DURATION=$(echo "($PROMPT_EXEC_TIME_STOP - $PROMPT_EXEC_TIME_START) * 1000" | bc -l)
 | 
			
		||||
    unset PROMPT_EXEC_TIME_START
 | 
			
		||||
}
 | 
			
		||||
format_time() {
 | 
			
		||||
    # Do some formatting to get nice time (e.g. 2m 12s) from miliseconds
 | 
			
		||||
    # $1 is the milisecond amount (int or float)
 | 
			
		||||
    # $2 is the precision (ms/s/m/h/d)
 | 
			
		||||
    local T=$1
 | 
			
		||||
    local D=$(echo "scale=0;$T/1000/60/60/24" | bc -l)
 | 
			
		||||
    local H=$(echo "scale=0;$T/1000/60/60%24" | bc -l)
 | 
			
		||||
    local M=$(echo "scale=0;$T/1000/60%60" | bc -l)
 | 
			
		||||
    local S=$(echo "scale=0;$T/1000%60" | bc -l)
 | 
			
		||||
    local MS=$(echo "scale=0;$T%1000" | bc -l)
 | 
			
		||||
 | 
			
		||||
    local precision=$2
 | 
			
		||||
    local out=""
 | 
			
		||||
    case "$precision" in
 | 
			
		||||
        "ms") [[ $MS > 0 ]] && out="$(printf "%dms" $MS) ${out}"; precision="s" ;&
 | 
			
		||||
        "s") [[ $S > 0 ]] && out="$(printf "%ds" $S) ${out}"; precision="m" ;&
 | 
			
		||||
        "m") [[ $M > 0 ]] && out="$(printf "%dm" $M) ${out}"; precision="h" ;&
 | 
			
		||||
        "h") [[ $H > 0 ]] && out="$(printf "%dh" $H) ${out}"; precision="d" ;&
 | 
			
		||||
        "d") [[ $D > 0 ]] && out="$(printf "%dd" $D) ${out}" ;;
 | 
			
		||||
        *) out="$T" ;; # Return $1 ($T) if precision wasn't specified/valid
 | 
			
		||||
    esac
 | 
			
		||||
    printf "$out"
 | 
			
		||||
}
 | 
			
		||||
display_cmd_time() {
 | 
			
		||||
    [[ $CMD_TIME_SHOW == 0 ]] && return
 | 
			
		||||
    [[ -z $PROMPT_EXEC_TIME_DURATION ]] && return
 | 
			
		||||
    # If the time duration is less than minimum time,
 | 
			
		||||
    # don't print the time taken
 | 
			
		||||
    [[ $PROMPT_EXEC_TIME_DURATION -lt $CMD_TIME_MINIMUM ]] && return
 | 
			
		||||
    local time_took="$(format_time "$PROMPT_EXEC_TIME_DURATION" "$CMD_TIME_PRECISION")"
 | 
			
		||||
    # Don't display if the time didn't give us output
 | 
			
		||||
    # this happens when all fields (seconds/minutes/...) are 0,
 | 
			
		||||
    # if we use milisecond precision, this will likely never happen
 | 
			
		||||
    # but with other precisions, it could
 | 
			
		||||
    [[ "$(expr length "$time_took")" == 0 ]] && return
 | 
			
		||||
    echo -n " ${LBLUE}took ${time_took}"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
setopt promptsubst  # enable command substitution in prompt
 | 
			
		||||
 | 
			
		||||
# Setup ZSH hooks to display the running time of commands
 | 
			
		||||
autoload -Uz add-zsh-hook
 | 
			
		||||
add-zsh-hook preexec exec_time_preexec_hook
 | 
			
		||||
add-zsh-hook precmd exec_time_precmd_hook
 | 
			
		||||
 | 
			
		||||
# Primary Prompt
 | 
			
		||||
[ "$EUID" -eq 0 ] && PS1="$RED%n$RESET" || PS1="$GREEN%n$RESET" # user
 | 
			
		||||
PS1+="$(foreign_prompt)"
 | 
			
		||||
PS1+="$(working_directory)"
 | 
			
		||||
PS1+="\$(git_prompt)"
 | 
			
		||||
PS1+="\$(display_cmd_time)"
 | 
			
		||||
PS1+=" $PURPLE%(!.#.$)$RESET " # Final symbol (# or $/»)
 | 
			
		||||
 | 
			
		||||
# Next line prompt
 | 
			
		||||
PS2="$RED\ $RESET"
 | 
			
		||||
 | 
			
		||||
# Right side prompt (on error)
 | 
			
		||||
# Right side prompt
 | 
			
		||||
RPS1=""
 | 
			
		||||
if [ $TERM = "linux" ]; then
 | 
			
		||||
	RPS1="%(?..${RED}%? X$RESET)"
 | 
			
		||||
    # Displaying cmd time here works, but often causes issues when we
 | 
			
		||||
    # resize the terminal, since right prompts can be annoying to deal
 | 
			
		||||
    # with when resizing. This would run relatively often so it makes
 | 
			
		||||
    # more sense to only use it in PS1 (left prompt), but if desired,
 | 
			
		||||
    # this can be uncommented
 | 
			
		||||
    #RPS1+="\$(display_cmd_time)"
 | 
			
		||||
 | 
			
		||||
    # If we find a non-zero return code, print it in the right prompt,
 | 
			
		||||
    # use X here, to avoid issues with TTY not having support for
 | 
			
		||||
    # a nicer unicode character that we use otherwise ("↵")
 | 
			
		||||
    RPS1+="%(?..${RED}%? X$RESET)"
 | 
			
		||||
else
 | 
			
		||||
	RPS1="%(?..${RED}%? ↵$RESET)"
 | 
			
		||||
    # Read comments for the section above.
 | 
			
		||||
    #RPS+="\$(display_cmd_time)"
 | 
			
		||||
    RPS1="%(?..${RED}%? ↵$RESET)"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -178,11 +178,16 @@ myKeys =
 | 
			
		|||
    , ("M-M1-k",    sendMessage MirrorExpand)   -- Expand vert window width
 | 
			
		||||
 | 
			
		||||
    -- Multimedia keys
 | 
			
		||||
    , ("<XF86AudioMute>",           spawn "amixer set Master toggle")
 | 
			
		||||
    , ("<XF86AudioLowerVolume>",    spawn "amixer set Master 5%- unmute")
 | 
			
		||||
    , ("<XF86AudioRaiseVolume>",    spawn "amixer set Master 5%+ unmute")
 | 
			
		||||
    , ("<XF86AudioMute>",           spawn "amixer set Master toggle")
 | 
			
		||||
    , ("<XF86MonBrightnessUp>",     spawn "brightness + 10 %")
 | 
			
		||||
    , ("<XF86MonBrightnessDown>",   spawn "brightness - 10 %")
 | 
			
		||||
    -- Map media keys to meta + arrows for keyboards without special keys
 | 
			
		||||
    , ("M-<Down>",                  spawn "amixer set Master 5%- unmute")
 | 
			
		||||
    , ("M-<Up>",                    spawn "amixer set Master 5%+ unmute")
 | 
			
		||||
    , ("M-<Right>",                 spawn "brightness + 10 %")
 | 
			
		||||
    , ("M-<Left>",                  spawn "brightness - 10 %")
 | 
			
		||||
    ]
 | 
			
		||||
        where nonNSP            = WSIs (return (\ws -> W.tag ws /= "NSP"))
 | 
			
		||||
              nonEmptyNonNSP    = WSIs (return (\ws -> isJust (W.stack ws) && W.tag ws /= "NSP"))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										13
									
								
								root/etc/grub.d/09_credentials
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										13
									
								
								root/etc/grub.d/09_credentials
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,13 @@
 | 
			
		|||
#!/bin/sh
 | 
			
		||||
exec tail -n +3 $0
 | 
			
		||||
 | 
			
		||||
# Setup GRUB credentials so that it isn't possible for anyone to change the
 | 
			
		||||
# boot parameters or use the command line, unless they know user/password pair
 | 
			
		||||
#set superusers="admin"
 | 
			
		||||
#password admin [unsafe plaintext password]
 | 
			
		||||
#password_pbkdf2 admin [safe grub-mkpasswd-pbkdf2 password]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Make OS Entries unrestricted, so that they can be booted into without prompting
 | 
			
		||||
# for user/password pair set above
 | 
			
		||||
#menuentry_id_option="--unrestricted $menuentry_id_option"
 | 
			
		||||
| 
						 | 
				
			
			@ -9,3 +9,4 @@ if [ ${grub_platform} == "efi" ]; then
 | 
			
		|||
		fwsetup
 | 
			
		||||
	}
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue