Skip to content

Commit

Permalink
Put IRB configuration file under XDG Base Directory
Browse files Browse the repository at this point in the history
  • Loading branch information
machupicchubeta committed Oct 29, 2023
1 parent b7d4503 commit 66c4150
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions .bash/variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@ export STARSHIP_CONFIG="$XDG_CONFIG_HOME/starship/config.toml"
export STARSHIP_CACHE="$XDG_CACHE_HOME/starship"
export INPUTRC="$XDG_CONFIG_HOME/readline/inputrc"
export RBENV_ROOT="$XDG_DATA_HOME/rbenv"
export IRBRC="$XDG_CONFIG_HOME/irb/irbrc"

export GPG_TTY=$(tty)
1 change: 1 addition & 0 deletions .zsh/variables.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ export STARSHIP_CONFIG="$XDG_CONFIG_HOME/starship/config.toml"
export STARSHIP_CACHE="$XDG_CACHE_HOME/starship"
export INPUTRC="$XDG_CONFIG_HOME/readline/inputrc"
export RBENV_ROOT="$XDG_DATA_HOME/rbenv"
export IRBRC="$XDG_CONFIG_HOME/irb/irbrc"

export GPG_TTY=$(tty)
13 changes: 5 additions & 8 deletions bin/put_settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if [ -d "$SETTINGS_PATH/.vim" ]; then
ln -s "$SETTINGS_PATH/.vim" "$XDG_CONFIG_HOME/nvim"
fi

for app in "git" "starship" "lsd" "sheldon" "bundle" "readline" "gem" "rspec" "tmux"; do
for app in "git" "starship" "lsd" "sheldon" "bundle" "readline" "gem" "irb" "rspec" "tmux"; do
if [ -L "$XDG_CONFIG_HOME/$app" ]; then
unlink "$XDG_CONFIG_HOME/$app"
fi
Expand Down Expand Up @@ -68,6 +68,10 @@ for app in "git" "starship" "lsd" "sheldon" "bundle" "readline" "gem" "rspec" "t
fi
done
fi

if [ "$app" = "irb" ] && [ ! -d "$XDG_DATA_HOME/$app" ]; then
mkdir --parents "$XDG_DATA_HOME/$app"
fi
done
unset -v app
unset -v shell
Expand All @@ -85,13 +89,6 @@ find "$SETTINGS_PATH"/.* -maxdepth 0 -type f -exec sh -c '
ln -s "$dot_file" "$HOME/$dot_filename"
' sh {} \;

if [ -L "$HOME/.irbrc" ]; then
unlink "$HOME/.irbrc"
fi
if [ -f "$GITHUB_REPOSITORIES_PATH/k0kubun/dotfiles/config/.irbrc" ]; then
ln -s "$GITHUB_REPOSITORIES_PATH/k0kubun/dotfiles/config/.irbrc" "$HOME/.irbrc"
fi

if [ -L /etc/my.cnf ]; then
sudo unlink /etc/my.cnf
fi
Expand Down
36 changes: 36 additions & 0 deletions config/irb/irbrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

autoload :Base64, 'base64'
autoload :CGI, 'cgi'
autoload :CSV, 'csv'
autoload :Digest, 'digest'
autoload :ERB, 'erb'
autoload :FileUtils, 'fileutils'
autoload :JSON, 'json'
autoload :Pathname, 'pathname'
autoload :Psych, 'psych'
autoload :Ripper, 'ripper'
autoload :SecureRandom, 'securerandom'
autoload :Shellwords, 'shellwords'
autoload :StringIO, 'stringio'
autoload :URI, 'uri/generic' # `autoload :URI, 'uri'` breaks Rails
autoload :YAML, 'yaml'
autoload :Zlib, 'zlib'

IRB.conf[:USE_AUTOCOMPLETE] = false
IRB.conf[:SAVE_HISTORY] = 1000
IRB.conf[:HISTORY_FILE] = File.join(ENV['XDG_DATA_HOME'], 'irb', 'history')
if defined?(IRB::Color) # just for consistency
clear = "\e[0m"
bold = "\e[1m"
green = "\e[32m"
blue = "\e[34m"
cyan = "\e[36m"
IRB.conf[:PROMPT][:DEFAULT] = {
PROMPT_I: "#{cyan}#{bold}%N#{clear}(#{green}#{bold}%m#{clear})[#{blue}%02n#{clear}:%i]> ",
PROMPT_N: "#{cyan}#{bold}%N#{clear}(#{green}#{bold}%m#{clear})[#{blue}%02n#{clear}:%i]> ",
PROMPT_S: "#{cyan}#{bold}%N#{clear}(#{green}#{bold}%m#{clear})[#{blue}%02n#{clear}:%i]%l ",
PROMPT_C: "#{cyan}#{bold}%N#{clear}(#{green}#{bold}%m#{clear})[#{blue}%02n#{clear}:%i]* ",
RETURN: "=> %s\n",
}
end

0 comments on commit 66c4150

Please sign in to comment.