• palordrolap@fedia.io
    link
    fedilink
    arrow-up
    6
    ·
    10 hours 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.

    • alias_qr_rainmaker@lemmy.worldOP
      link
      fedilink
      arrow-up
      6
      arrow-down
      1
      ·
      14 hours 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
          5
          ·
          13 hours 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
            1
            ·
            4 hours 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
    4
    ·
    edit-2
    7 hours 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.

      • alias_qr_rainmaker@lemmy.worldOP
        link
        fedilink
        arrow-up
        5
        ·
        14 hours 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