Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"ghcr.io/devcontainers-extra/features/devcontainers-cli:1": {}
},
// "forwardPorts": [5000],
"onCreateCommand": ".devcontainer/scripts/on-create.sh",
"updateContentCommand": ".devcontainer/scripts/update-content.sh",
"postCreateCommand": ".devcontainer/scripts/post-create.sh",
"customizations": {
Expand Down Expand Up @@ -55,7 +56,8 @@
"files.autoSaveWorkspaceFilesOnly": true,
"terminal.integrated.cursorBlinking": true,
"telemetry.editStats.enabled": false,
"bashIde.explainshellEndpoint": "http://127.0.0.1:5000"
"bashIde.explainshellEndpoint": "http://127.0.0.1:5000",
"shellcheck.enableQuickFix": false
}
}
},
Expand Down
151 changes: 151 additions & 0 deletions .devcontainer/scripts/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# shellcheck disable=SC2148

BASHRC="$HOME/.bashrc"
ALIASES="$HOME/.bash_aliases"
INPUTRC="$HOME/.inputrc"

log "Creating $ALIASES file..."
cat <<'EOF' >"$ALIASES"
alias ls="lsd --color auto"
alias ll="lsd -alF --color auto"
alias la="lsd -A --color auto"
alias cat="bat --color auto --style plain"
alias hx="hx --vsplit"
alias helix=hx
alias vim=hx
EOF

log "Creating $INPUTRC file..."
cat <<'EOF' >"$INPUTRC"
$include /etc/inputrc

set blink-matching-paren on
set colored-completion-prefix on
set completion-ignore-case on
set completion-map-case on
set show-all-if-unmodified on
set show-all-if-ambiguous on
TAB: menu-complete
"\e[Z": menu-complete-backward
EOF

log "Creating $BASHRC..."
cat <<'EOF' >"$BASHRC"
case $- in
*i*) ;;
*) return;;
esac

HISTCONTROL=ignoreboth
shopt -s histappend
HISTSIZE=-1
HISTFILESIZE=-1
HISTDUP="erase"
HISTTIMEFORMAT="%FT%T "

shopt -s checkwinsize
shopt -s globstar

[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi

case "$TERM" in
xterm-color | *-256color) color_prompt=yes ;;
esac

if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
color_prompt=yes
else
color_prompt=
fi
fi

if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[$(tput setaf 39)\]\u\[$(tput setaf 81)\]@\[$(tput setaf 77)\]\h \[$(tput setaf 226)\]\w \[$(tput sgr0)\]\n❯ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

case "$TERM" in
xterm* | rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*) ;;
esac

if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
fi

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

if [ -f ~/.bash_env ]; then
. ~/.bash_env
fi

if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
# bash theme - partly inspired by https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/robbyrussell.zsh-theme
__bash_prompt() {
local userpart='`export XIT=$? \
&& [ ! -z "${GITHUB_USER:-}" ] && echo -n "\[\033[0;32m\]@${GITHUB_USER:-} " || echo -n "\[\033[0;32m\]\u " \
&& [ "$XIT" -ne "0" ] && echo -n "\[\033[1;31m\]➜" || echo -n "\[\033[0m\]➜"`'
local gitbranch='`\
if [ "$(git config --get devcontainers-theme.hide-status 2>/dev/null)" != 1 ] && [ "$(git config --get codespaces-theme.hide-status 2>/dev/null)" != 1 ]; then \
export BRANCH="$(git --no-optional-locks symbolic-ref --short HEAD 2>/dev/null || git --no-optional-locks rev-parse --short HEAD 2>/dev/null)"; \
if [ "${BRANCH:-}" != "" ]; then \
echo -n "\[\033[0;36m\](\[\033[1;31m\]${BRANCH:-}" \
&& if [ "$(git config --get devcontainers-theme.show-dirty 2>/dev/null)" = 1 ] && \
git --no-optional-locks ls-files --error-unmatch -m --directory --no-empty-directory -o --exclude-standard ":/*" > /dev/null 2>&1; then \
echo -n " \[\033[1;33m\]✗"; \
fi \
&& echo -n "\[\033[0;36m\]) "; \
fi; \
fi`'
local lightblue='\[\033[1;34m\]'
local removecolor='\[\033[0m\]'
PS1="${userpart} ${lightblue}\w ${gitbranch}${removecolor}\n❯ "
unset -f __bash_prompt
}
__bash_prompt
export PROMPT_DIRTRIM=4

# Check if the terminal is xterm
if [[ "$TERM" == "xterm" ]]; then
# Function to set the terminal title to the current command
preexec() {
local cmd="${BASH_COMMAND}"
echo -ne "\033]0;${USER}@${HOSTNAME}: ${cmd}\007"
}

# Function to reset the terminal title to the shell type after the command is executed
precmd() {
echo -ne "\033]0;${USER}@${HOSTNAME}: ${SHELL}\007"
}

# Trap DEBUG signal to call preexec before each command
trap 'preexec' DEBUG

# Append to PROMPT_COMMAND to call precmd before displaying the prompt
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }precmd"
fi

source <(bat --completion bash)
source <(fzf --bash)

FZF_COMPLETION_AUTO_COMMON_PREFIX=true
FZF_COMPLETION_AUTO_COMMON_PREFIX_PART=true
EOF
10 changes: 10 additions & 0 deletions .devcontainer/scripts/on-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail

SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=.devcontainer/scripts/utils.sh
source "${SCRIPTS_DIR}/utils.sh"
# shellcheck source=.devcontainer/scripts/config.sh
source "${SCRIPTS_DIR}/config.sh"

npm install --silent --quiet --location=global npm@latest
10 changes: 6 additions & 4 deletions .devcontainer/scripts/post-create.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail
#set -x

log(){ printf '[post-create] %s\n' "$*"; }
err(){ printf '[post-create][ERROR] %s\n' "$*"; }
warn(){ printf '[post-create][WARN] %s\n' "$*"; }
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=.devcontainer/scripts/utils.sh
source "${SCRIPTS_DIR}/utils.sh"

log "This script is run after update-content.sh"

Expand Down Expand Up @@ -37,7 +38,8 @@ if command -v docker >/dev/null 2>&1; then
-d "$EXPLAINSHELL_MONGODB_IMAGE"

log "Importing explainshell db dump in the background..."
docker exec -t "$EXPLAINSHELL_MONGODB_CONTAINER" mongorestore --archive --gzip < "$work_location/dump.gz" &> "$work_location/$(date +%Y%m%dT%k%M%)-mongorestore.log" &
docker exec -t "$EXPLAINSHELL_MONGODB_CONTAINER" mongorestore \
--archive --gzip < "$work_location/dump.gz" &> "$work_location/$(date +%Y%m%dT%k%M%)-mongorestore.log" &

log "Starting explainshell container..."
docker container run \
Expand Down
Loading