• cyrl@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    6 hours ago

    I’d much rather keep my rc organised, so I just have a pair of aliases to quickly open it in an editor and another to reload.

    alias cfge="$EDITOR ~/.bashrc"
    alias cfgs="source ~/.bashrc"
    
  • arran 🇦🇺@aussie.zone
    link
    fedilink
    arrow-up
    5
    ·
    18 hours ago

    And then you can immediately solve the issue with programs arbitrarily adding things to your rc file by running:

    add exit
    
    • alias_qr_rainmaker@lemmy.worldOP
      link
      fedilink
      arrow-up
      1
      ·
      10 hours ago

      programs arbitrarily adding things to your .rc

      umm why would you ever do that, i only add to my .rc when i come up with an alias i know i’m gonna use a bunch

      • arran 🇦🇺@aussie.zone
        link
        fedilink
        arrow-up
        2
        ·
        6 hours ago

        When I’m contracting at a client sometimes they have boot strap scripts which push configuration out to your rc files that I want to gate. (Usually b/c I am using my own equipment or doing something a little strange.)

        • alias_qr_rainmaker@lemmy.worldOP
          link
          fedilink
          arrow-up
          1
          ·
          4 hours ago

          When I’m contracting, I…

          uh…

          dude this is just a hobby for me, I didn’t get serious about it until like a few months ago. Before that I was recovering from a traumatic brain injury, and before that I couldn’t live on my own, and right before that it was December 2014. My first programming class was back in 2005, and I went to a coding bootcamp, but I haven’t actually made an effort to get hired until my fourth manic episode in November of this year.

          • arran 🇦🇺@aussie.zone
            link
            fedilink
            arrow-up
            1
            ·
            4 hours ago

            Sorry. I didn’t mean to offend and it’s not an attack at the project in anyway - sorry if it came across that way. I think tools to help you manage RC files are great. I just dislike tools that automatically inject themselves automatically (like rvm), my statement was in no regards about the tool you wrote.

    • alias_qr_rainmaker@lemmy.worldOP
      link
      fedilink
      arrow-up
      8
      arrow-down
      1
      ·
      2 days ago

      same shit, just replace zsh with bash. the syntaxes for the two aren’t QUITE the same but they’re so fuckin close they might as well be one language

        • alias_qr_rainmaker@lemmy.worldOP
          link
          fedilink
          arrow-up
          6
          ·
          2 days ago

          basically, yeah. y’all aren’t gonna believe this but i just found out the other day that you don’t need the cd with zsh. you can just type in the directory name. i don’t even know what else is different, i learned how to use the terminal from watching youtube linux tutorials so i might be just a lost bashbro

          • valaramech@fedia.io
            link
            fedilink
            arrow-up
            2
            ·
            1 day ago

            I wouldn’t be surprised if all shells have some form of that, but not enabled by default. I know Bash does, but I’ve never turned it on.

  • BartyDeCanter@lemmy.sdf.org
    link
    fedilink
    arrow-up
    10
    ·
    edit-2
    2 days ago

    My version is definitely wordier, but I like it.

    add-alias() {
      if [[ -z "$1"  ||  -z "$2" ]]; then
        echo "Useage: add-alias <alias_name> \"<command_to_alias>\""
        return 1
      fi
      echo "alias $1='$2'" >> ~/.bash_aliases
      source ~/.bash_aliases
      echo "Alias '$1' for command '$2' added and sourced."
      
    }
    

    And, of course, the first thing I test it with is $ add-alias alias-add add-alias.

  • palordrolap@fedia.io
    link
    fedilink
    arrow-up
    8
    ·
    2 days ago

    I have an alias called save_aliases that does alias > ~/.bash_aliases. alias on its own just dumps all the existing aliases to the terminal in a format that can be parsed by Bash.

    I felt especially clever when I came up with that and used it to save itself.

    Bonus fact: ${BASH_ALIASES["name-here"]} is a way to get at the contents of an alias without resorting sed or cut shenanigans on the output of the alias command.

    • Pankkake@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      1 day ago

      Bonus fact: ${BASH_ALIASES["name-here"]} is a way to get at the contents of an alias without resorting sed or cut shenanigans on the output of the alias command.

      Doesn’t alias name-here already do that? That or I didn’t get what you mean.

      • palordrolap@fedia.io
        link
        fedilink
        arrow-up
        1
        ·
        23 hours ago

        alias name-here yields the line alias name-here='contents-of-alias-here' as output, and if you want just the part between the single quotes from that, sed, cut or, come to think of it, related shell tricks that do the same thing, would be needed to capture and convert it.

        ${BASH_ALIASES["name-here"]} is a name for what’s only between those single quotes.

        For example, I have a lot of preferences built into my alias for ‘ls’. Occasionally I want to run watch ls -l somefilespec to watch a directory listing for changes to a file. But commands fed to watch don’t go through the alias mechanism, leaving the output somewhat different to my preferences.

        It’s wordy, but watch ${BASH_ALIASES["ls"]} -l somefilespec mostly* achieves what I want.

        * Unfortunately, watch also causes the stripping of colour codes and I have --color=auto, not --color=force in my ls alias, so it’s by no means perfect - I have add the latter if I want colour - but I don’t have to type the rest of the preferences I have in there.

        FWIW, my ls alias is currently:

        alias ls='LC_ALL=C ls --color=auto --group-directories-first --time-style="+ %F %T"'
        
      • alias_qr_rainmaker@lemmy.worldOP
        link
        fedilink
        arrow-up
        6
        ·
        2 days ago

        i like my variable names and aliases to sound like natural english, which means you have to conjugate the functions differently. they’re supposed to be third person singular

        sorry guys i’m not a computer nerd but i’m a linguist so i like languages, including the computer ones

        • toynbee@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          1 day ago

          You must be a linguist; the only other person I’ve ever witnessed using the word “conjugate” was my mother, who taught me basically everything I know about grammar.

    • Digit@lemmy.wtf
      link
      fedilink
      English
      arrow-up
      3
      ·
      1 day ago

      As a fish user i relate to this

      Because we fish users don’t need to write a new function for this, because we already have an option on alias for it?

      In man alias in fish:

               -s or --save
                Saves the function created by the alias into your fish configuration directory using funcsave.
      

      In man alias in bash:

      OPTIONS

        None.
      

      (PS, though, still perhaps handy, if not liking how alias -s saves your aliases.)