Skip to content

Instantly share code, notes, and snippets.

@lzlrd
Last active August 27, 2024 19:29
Show Gist options
  • Save lzlrd/b5732f9bf89834f9e117c804e8e5bd0d to your computer and use it in GitHub Desktop.
Save lzlrd/b5732f9bf89834f9e117c804e8e5bd0d to your computer and use it in GitHub Desktop.
Prompts
#! /usr/bin/env bash
# shellcheck disable=SC1090,SC1091
shopt -s histappend
mkjump() {
mkdir -p "$1"
cd "$1" || echo "Failed to cd into $1." && return 1
}
EDITOR="nano"
export EDITOR
HISTCONTROL="ignoredups"
export HISTCONTROL
HISTFILESIZE="100000"
export HISTFILESIZE
HISTSIZE="100000"
export HISTSIZE
PAGER="cat"
export PAGER
# This hack casuses a newline to be placed before each prompt, but only after
# the first initialisation.
# shellcheck disable=SC2089
PROMPT_COMMAND="history -a; export PROMPT_COMMAND=\"history -a; echo\""
# shellcheck disable=SC2090
export PROMPT_COMMAND
PS1="\[\e[m\]\[\e[34m\]┌──────[$([[ $EUID == 0 ]] && printf "\[\e[31m\]" || printf "\[\e[32m\]")\u\[\e[33m\]@$([[ $EUID == 0 ]] && printf "\[\e[31m\]" || printf "\[\e[32m\]")\h\[\e[34m\]]─[$([[ $EUID == 0 ]] && printf "\[\e[31m\]" || printf "\[\e[32m\]")\w\[\e[34m\]]\n\[\e[34m\]└── \[\e[33m\]\\$ \[\e[m\]"
export PS1
PS2="\[\e[m\]\[\e[33m\]> \[\e[m\]"
export PS2
# The complementary to the above hack which places a newline before each prompt.
alias clear='unset PROMPT_COMMAND; clear; PROMPT_COMMAND="history -a; export PROMPT_COMMAND=echo"'
alias e='emacs'
alias grep='grep --color=auto'
alias hgrep='history | grep'
alias ls='ls --color=auto'
alias ll='ls -lh'
case "$(hostname)" in
"cerus")
update() {
:
}
;;
esac
PROMPT=┌──────[Diab Neiroukh@terrarium]─[$P]$_└── $$
function Clear-Host {
$env:pwshFirstPrompt = $true
[System.Console]::Clear()
}
# The IIf function has been taken from https://stackoverflow.com/a/25682508.
function IIf ($If, $Then, $Else) {
If ($If -IsNot "Boolean") {$_ = $If}
If ($If) {If ($Then -is "ScriptBlock") {&$Then} Else {$Then}}
Else {If ($Else -is "ScriptBlock") {&$Else} Else {$Else}}
}
function Prompt {
$esc = [char]27
$isAdmin = [Bool](New-Object Security.Principal.WindowsPrincipal ([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
$pwdWithTilde = (Get-Location) -Replace [Regex]::Escape($HOME), "~"
Write-Host "$esc[m$esc[34m$(IIf ($env:pwshFirstPrompt -Eq $false) "`r`n" "")──────[$(IIf $isAdmin "$esc[31m" "$esc[32m")$env:UserName$esc[33m@$(IIf $isAdmin "$esc[31m" "$esc[32m")$([System.Net.Dns]::GetHostName())$esc[34m]─[$(IIf $isAdmin "$esc[31m" "$esc[32m")$pwdWithTilde$esc[34m]`r`n└── $esc[33m$(IIf $isAdmin '#' '$')$esc[m" -NoNewline
$env:pwshFirstPrompt = $false
return " "
}
if ($null -Eq $env:pwshFirstPrompt) {
$env:pwshFirstPrompt = $true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment