Skip to content
This repository was archived by the owner on Aug 30, 2026. It is now read-only.
Open
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
2 changes: 1 addition & 1 deletion bin/omakub-sub/menu.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

if [ $# -eq 0 ]; then
SUB=$(gum choose "Theme" "Font" "Update" "Install" "Uninstall" "Manual" "Quit" --height 10 --header "" | tr '[:upper:]' '[:lower:]')
SUB=$(gum choose "Theme" "Font" "Shell" "Update" "Install" "Uninstall" "Manual" "Quit" --height 11 --header "" | tr '[:upper:]' '[:lower:]')
else
SUB=$1
fi
Expand Down
162 changes: 162 additions & 0 deletions bin/omakub-sub/shell-switch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#!/bin/bash

target_shell=$1
current_shell=$(basename "$SHELL")
timestamp=$(date +%Y%m%d_%H%M%S)
backup_dir="$HOME/.omakub-shell-backups/$timestamp"

# ============================================
# Confirmation
# ============================================
echo ""
gum style --border double --padding "1 2" --border-foreground 212 \
"SHELL SWITCH" \
"" \
"From: $current_shell" \
"To: $target_shell" \
"" \
"This will:" \
" - Backup current config" \
" - Install fresh $target_shell config" \
" - Change default login shell" \
"" \
"Note: You'll need to manually copy" \
"your customizations to the new shell."

echo ""
if ! gum confirm "Proceed?"; then
echo "Cancelled."
sleep 1
return 0
fi

echo ""
gum style --foreground 214 "Administrator privileges required."
echo ""

# ============================================
# Backup
# ============================================
echo "Creating backup..."
mkdir -p "$backup_dir"

case $current_shell in
bash)
[ -f ~/.bashrc ] && cp ~/.bashrc "$backup_dir/"
[ -f ~/.inputrc ] && cp ~/.inputrc "$backup_dir/"
;;
zsh)
[ -f ~/.zshrc ] && cp ~/.zshrc "$backup_dir/"
;;
esac
echo "Backup saved: $backup_dir"

# ============================================
# Extract customizations
# ============================================
echo "Extracting customizations..."
customizations="$backup_dir/customizations.sh"

case $current_shell in
bash)
if [ -f ~/.bashrc ]; then
# Extract lines after the Omakub source line and EDITOR settings
sed -n '/^# Add your customizations/,$p' ~/.bashrc > "$customizations" 2>/dev/null
# If that didn't work, try extracting after SUDO_EDITOR
if [ ! -s "$customizations" ]; then
sed -n '/^export SUDO_EDITOR/,$p' ~/.bashrc | tail -n +2 > "$customizations" 2>/dev/null
fi
fi
;;
zsh)
if [ -f ~/.zshrc ]; then
sed -n '/^# Add your customizations/,$p' ~/.zshrc > "$customizations" 2>/dev/null
if [ ! -s "$customizations" ]; then
sed -n '/^export SUDO_EDITOR/,$p' ~/.zshrc | tail -n +2 > "$customizations" 2>/dev/null
fi
fi
;;
esac

if [ -s "$customizations" ]; then
lines=$(wc -l < "$customizations")
echo "Found $lines lines to migrate"
else
rm -f "$customizations"
echo "No customizations found"
fi

# ============================================
# Install target shell
# ============================================
case $target_shell in
zsh)
if ! command -v zsh &> /dev/null; then
echo "Installing Zsh..."
sudo apt install -y zsh
if ! command -v zsh &> /dev/null; then
gum style --foreground 196 "Installation failed!"
return 1
fi
echo "Zsh installed"
fi

zsh_path=$(which zsh)
grep -q "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells > /dev/null

echo "Configuring Zsh..."
cp $OMAKUB_PATH/configs/zshrc ~/.zshrc

echo "Setting default shell..."
sudo chsh -s "$zsh_path" $USER
echo "Default shell: Zsh"
;;

bash)
bash_path=$(which bash)

echo "Configuring Bash..."
cp $OMAKUB_PATH/configs/bashrc ~/.bashrc
cp $OMAKUB_PATH/configs/inputrc ~/.inputrc

echo "Setting default shell..."
sudo chsh -s "$bash_path" $USER
echo "Default shell: Bash"
;;
esac

# Record choice
echo "$target_shell" > ~/.local/share/omakub/.shell-choice

# ============================================
# Complete
# ============================================
echo ""
gum style --border double --padding "1 2" --border-foreground 82 \
"SWITCH COMPLETE" \
"" \
"Changed: $current_shell -> $target_shell" \
"Backup: $backup_dir"

if [ -f "$customizations" ]; then
echo ""
gum style --foreground 214 \
"Your customizations were saved to:" \
" $customizations" \
"" \
"Review and copy them to your new" \
"shell config (~/.${target_shell}rc)." \
"Some commands may need adjustment" \
"for the new shell (e.g., init bash -> init zsh)."
fi

echo ""
gum style \
"To activate:" \
" - Log out and back in, OR" \
" - Run: exec $target_shell"

echo ""
if gum confirm "Start $target_shell now?"; then
exec $target_shell
fi
64 changes: 64 additions & 0 deletions bin/omakub-sub/shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

current_shell=$(basename "$SHELL")

echo ""
gum style --foreground 212 --bold "Shell Management"
echo ""
echo "Current shell: $current_shell"
echo ""

CHOICE=$(gum choose "Switch to Bash" "Switch to Zsh" "Shell Info" "<< Back" --header "")

case "$CHOICE" in
"Switch to Bash")
if [[ "$current_shell" == "bash" ]]; then
gum style --foreground 208 "Already using Bash!"
sleep 2
else
source $OMAKUB_PATH/bin/omakub-sub/shell-switch.sh bash
fi
;;

"Switch to Zsh")
if [[ "$current_shell" == "zsh" ]]; then
gum style --foreground 208 "Already using Zsh!"
sleep 2
else
source $OMAKUB_PATH/bin/omakub-sub/shell-switch.sh zsh
fi
;;

"Shell Info")
echo ""
echo "Current shell: $current_shell"
echo "Default shell: $(getent passwd $USER | cut -d: -f7)"
echo ""
echo "Bash: $(bash --version | head -1)"
if command -v zsh &> /dev/null; then
echo "Zsh: $(zsh --version)"
else
echo "Zsh: Not installed"
fi
echo ""
echo "Shell choice file: ~/.local/share/omakub/.shell-choice"
if [ -f ~/.local/share/omakub/.shell-choice ]; then
echo "Recorded choice: $(cat ~/.local/share/omakub/.shell-choice)"
fi
echo ""
echo "Config location:"
case "$current_shell" in
bash) echo " ~/.bashrc" ;;
zsh) echo " ~/.zshrc" ;;
esac
echo ""
read -p "Press Enter to continue..."
;;

*)
# Back to menu
;;
esac

clear
source $OMAKUB_PATH/bin/omakub
7 changes: 7 additions & 0 deletions configs/zshrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source ~/.local/share/omakub/defaults/zsh/rc

# Editor used by CLI
export EDITOR="nvim"
export SUDO_EDITOR="$EDITOR"

# Add your customizations below this line
14 changes: 12 additions & 2 deletions defaults/bash/rc
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# ============================================
# OMAKUB BASH RC - Main Loader
# ============================================

# Bash-specific settings first
source ~/.local/share/omakub/defaults/bash/shell
source ~/.local/share/omakub/defaults/bash/aliases
source ~/.local/share/omakub/defaults/bash/functions

# Shared configs (bash/zsh compatible)
source ~/.local/share/omakub/defaults/shared/environment.sh
source ~/.local/share/omakub/defaults/shared/aliases.sh
source ~/.local/share/omakub/defaults/shared/functions.sh

# Bash-specific configs
source ~/.local/share/omakub/defaults/bash/prompt
source ~/.local/share/omakub/defaults/bash/init
17 changes: 7 additions & 10 deletions defaults/bash/shell
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# History control
# ============================================
# OMAKUB BASH-SPECIFIC SHELL SETTINGS
# ============================================

# Bash-specific options
shopt -s histappend
HISTCONTROL=ignoreboth
HISTSIZE=32768
HISTFILESIZE="${HISTSIZE}"
set +h # Disable hashing for dynamic PATH

# Autocompletion
# Bash completion
source /usr/share/bash-completion/bash_completion

# Set complete path
export PATH="./bin:$HOME/.local/bin:$HOME/.local/share/omakub/bin:$PATH"
set +h

export OMAKUB_PATH="$HOME/.local/share/omakub"
6 changes: 5 additions & 1 deletion defaults/bash/aliases → defaults/shared/aliases.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# ============================================
# OMAKUB SHARED ALIASES
# Compatible with: bash, zsh
# ============================================

# File system
alias ls='eza -lh --group-directories-first --icons=auto'
alias lsa='ls -a'
Expand All @@ -13,7 +18,6 @@ alias ...='cd ../..'
alias ....='cd ../../..'

# Tools
n() { if [ "$#" -eq 0 ]; then nvim .; else nvim "$@"; fi; }
alias g='git'
alias d='docker'
alias r='rails'
Expand Down
14 changes: 14 additions & 0 deletions defaults/shared/environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ============================================
# OMAKUB SHARED ENVIRONMENT
# Compatible with: bash, zsh
# ============================================

# History
export HISTSIZE=32768
export HISTFILESIZE="${HISTSIZE}"

# Path setup
export PATH="./bin:$HOME/.local/bin:$HOME/.local/share/omakub/bin:$PATH"

# Omakub
export OMAKUB_PATH="$HOME/.local/share/omakub"
37 changes: 28 additions & 9 deletions defaults/bash/functions → defaults/shared/functions.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# ============================================
# OMAKUB SHARED FUNCTIONS
# Compatible with: bash, zsh
# ============================================

# Neovim launcher
n() {
if [ "$#" -eq 0 ]; then
nvim .
else
nvim "$@"
fi
}

# Compression
compress() { tar -czf "${1%/}.tar.gz" "${1%/}"; }
alias decompress="tar -xzf"
Expand Down Expand Up @@ -112,21 +126,26 @@ app2folder-remove() {

if [[ "$CURRENT_APPS" == *"$DESKTOP_FILE"* ]]; then
local RAW_LIST=$(echo "$CURRENT_APPS" | tr -d "[]'")
IFS=',' read -ra APPS_ARRAY <<< "$RAW_LIST"

# Filter out the app to be removed
local NEW_APPS=()
for app in "${APPS_ARRAY[@]}"; do
# Split by comma - compatible with both bash and zsh
local NEW_APPS=""
local OLDIFS="$IFS"
IFS=','
for app in $RAW_LIST; do
IFS="$OLDIFS"
app=$(echo "$app" | xargs) # trim spaces
if [[ "$app" != "$DESKTOP_FILE" && -n "$app" ]]; then
NEW_APPS+=("'$app'")
if [[ -n "$NEW_APPS" ]]; then
NEW_APPS="$NEW_APPS,'$app'"
else
NEW_APPS="'$app'"
fi
fi
IFS=','
done
IFS="$OLDIFS"

# Join list again
local NEW_LIST=$(IFS=, ; echo "${NEW_APPS[*]}")

gsettings set "$SCHEMA" apps "[$NEW_LIST]"
gsettings set "$SCHEMA" apps "[$NEW_APPS]"
fi
}

Expand Down
Loading