Skip to content

Improve .irbrc's loading behaviour #674

Closed

Description

@st0012

I noticed 2 "surprising" .irbrc loading behaviour recently:

Lack of hierarchy on rc file loading

Unlike many other tools that have "project level" and "user level" configurations, IRB only accepts a single .irbrc file through a fixed loading order.

For example, it doesn't load project/.irbrc if ~/.irbrc is present.

This is unintuitive to most users as popular tools like Pry or VS Code both have "user level" and "project level" configurations. And they usually load "user level" configs first, and allow "project level" configs to override them.

$ pry        
~/.pryrc loaded
project/.pryrc loaded
[1] pry(main)> 

.irb_history is always placed at the same place as .irbrc is defined

This is also not an intuitive design. Most of the time, .irb_history should not be inside the project folder. So the current reality is, if a project wants to define .irbrc for all its developers, .irb_history needs to be added to .gitignore or the project needs to configure IRB.conf[:HISTORY_FILE] (example).

Activity

  1. ktopolski commented on Dec 9, 2023

    @ktopolski

    Hello 👋

    First time irb contributor here - just wanted to say thank you for maintaining Ruby's core tool! 🙏

    I'd love to contribute to give back to the community so I picked first part of the issue and made a PR. I feel like I'm walking in the dark a bit, but managed to test it on the "local"(github codespace) environment and it passes automatic tests as well. I wasn't able to verify the yamatanooroti due to codespace limitations - might get back to it on local environment next week.

    I'm extremely open to feedback - would love to contribute more to irb in the future!

  2. elfham commented on Mar 13, 2024

    @elfham

    Since #859, ~/.config/irb/irbrc is loaded twice when $XDG_CONFIG_HOME is set.

    % irb
    irb(main):001> IRB.rc_files.select { |rc| File.exist?(rc) }
    => []
    irb(main):002> exit
    % echo "puts __FILE__" > ~/.config/irb/irbrc
    % irb
    /home/elfham/.config/irb/irbrc
    irb(main):001> IRB.rc_files.select { |rc| File.exist?(rc) }
    => ["/home/elfham/.config/irb/irbrc"]
    irb(main):002> exit
    % export XDG_CONFIG_HOME=~/.config
    % irb
    /home/elfham/.config/irb/irbrc
    /home/elfham/.config/irb/irbrc
    irb(main):001> IRB.rc_files.select { |rc| File.exist?(rc) }
    => ["/home/elfham/.config/irb/irbrc", "/home/elfham/.config/irb/irbrc"]
    irb(main):002> exit
    % 
    

    IMHO, only one irbrc file should be loaded at each "user level" and "project level".

    For example, if there are 4 files as below,

    • user level
      • ~/.config/irb/irbrc
      • ~/.irbrc
    • project level
      • ./.irbrc
      • ./_irbrc

    only ~/.config/irb/irbrc and ./.irbrc should be loaded and others should be ignored.

    How do you think about this?

  3. elfham commented on Mar 13, 2024

    @elfham

    By the way, since #859, ~/.irbrc is loaded twice at ~/ if HOME directory is symlinked.

    % LANG=C ls -l /home/elfham
    lrwxr-xr-x  1 root wheel 23 Jan 20  2014 /home/elfham@ -> /mnt/nfs/home/elfham
    % echo "puts __FILE__" > ~/.irbrc
    % cd ~/
    % irb
    /home/elfham/.irbrc
    /mnt/nfs/home/elfham/.irbrc
    irb(main):001> exit
    % 
    
  4. ktopolski commented on Apr 18, 2024

    @ktopolski

    Hey @elfham 👋

    Sorry so much for disappearing so suddenly! I really hoped to finish this one and then life took an unexpected turn - deeply sorry about that. Also thank you to @hahmed & @tompng for working on this one 🙏

    I hope I'll be able to make up for this one as I'll have more time for OSS soon🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementrubyconf-hackdays

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions