• 30 Posts
  • 727 Comments
Joined 2 years ago
cake
Cake day: June 15th, 2023

help-circle



  • You don’t need to understand a command in order to copy paste an alias or Bash function. Especially newcomers could tend to do it, without knowing what the command actually does. We are also in a posting with helpful commands, so its double harmful. And you doubling down without adding any sort of disclaimer shows you don’t care.


  • There is an expression, Linux isn’t free it costs you your time.

    Just because someone said it does not make it true and certainly, I don’t have to live after that expression. It kind of is a catch all phrase to justify (or not to justify) everything. It could also be used as an argument for “Vibe Coding” (I hate that term…).

    I mean this argument about Linux does not apply to every single application (you apply it right now here to some random Python script). In example Windows, MacOS, Android, nothing is free and costs you your time. The question is, how you want spent your time. And I enjoy writing programs and scripts for various reasons.

    I personally think reinventing the wheel is great. Why? It makes you learn and do it. It makes you less dependent. The end result might not be the most polished one, but also if nobody reinvents the wheel, then we have no competition. Sure you should not reinvent everything, there is a balance act to make. And this balance is different for everyone else.


  • BTW, I’m not saying the way I am going and doing this is the right one. In the end I use additional packages when needed, BeautifulSoup as an example to make life really easier. But that is something specific to that script. Stuff like click and argparse is more than a single script, because when I switch to click then all my future scripts would depend on it. And I feel more comfortable with a solution that is already built-in (stdlib) if its not too bad.

    I don’t see click as a required package that I really need. And that is also true for many other packages, such as requests one.


  • I use external packages for compiled languages. For scripting languages like Python, it makes it ab it harder to use. Because people are forced to install dependencies. I don’t like that (unless its a shell script, but that is by its nature a dependency hell).

    And for Python, I usually deliver the script as a single .py file, without requirements or special instructions, no typical file structure as well. And your argument just because other popular packages use a specific library does not mean I have to use it too. I don’t care what libraries other popular packages use, at least in context to my program / script.




  • It supports both and depending on the situation its more procedural or more object oriented. Do you consider the standard library as part of the language and are you forced to use it? Then certainly the object oriented parts of the language would be forced to use and therefore it is object oriented. Or do you only evaluate the language and its features itself? In that case, Python supports object oriented programming with classes and objects, but you are not forced to use it.

    Are we talking about the language features itself or the produced programs with it in the real world?

    So regardless if you look at the language itself or the common standard library that most Python programs use, objects and classes are an part of the language. Even if you write simple procedural scripts, does not take away that Python itself is a more object oriented programming language.


  • Nice. There is a reason why the standard library of Python does not get rid of optparse. optparse was I think marked to be removed in the future, but its no longer deprecated and will stay in the library.

    Click looks good and I would have looked in more detail. The problem to me is, it is a dependency. I usually write and try to write Python programs without external library dependency, unless it is absolutely necessary (like GUI or BeautifulSoup). Click “might” be a better alternative, but it is “only” something that does it a little bit better. This is not a reason for me to use an external library.


  • Here is on that I actually don’t use, but want to use it in scripts. It is meant to be used by piping it. It’s simple branch with user interaction. I don’t even know if there is a standard program doing exactly that already.

    # usage: yesno [prompt]
    # example:
    #   yesno && echo yes
    #   yesno Continue? && echo yes || echo no
    yesno() {
        local prompt
        local answer
        if [[ "${#}" -gt 0 ]]; then
            prompt="${*} "
        fi
        read -rp "${prompt}[y/n]: " answer
        case "${answer}" in
        [Yy0]*) return 0 ;;
        [Nn1]*) return 1 ;;
        *) return 2 ;;
        esac
    }
    

  • For the newer version of program, that’s why we have the $PATH. You put your program into one of the directories that is in your $PATH variable, then you can access your script or program from any of these like a regular program. Check the directories with echo "$PATH" | tr ':' '\n'

    My custom scripts and programs directory is “~/.local/bin”, but it has to be in the $PATH variable too. Every program and script i put there can be run like any other program. You don’t even need an alias for this specific program in example.


  • I’m not sure what you mean with the question. If you have any alias like alias rm='ls -l' in your .bashrc in example, then you cannot use the original command rm anymore, as it is aliased to something else. I’m speaking about the terminal, when you enter the command. However, if you put a backslash in front of it like \rm in the terminal, then the alias for it is ignored and the original command is executed instead.

    Edit: Made a more clear alias example.




  • i also have the chmod one, but mine is named just x:

    alias x='chmod +x'
    

    I also have the yt-dlp "$(wl-paste)" one, but its build around a custom script. So sharing it here makes no sense. Its funny how often we do same thing in different ways (extracting or creating archives in example). Often aliases get development into function and then they turn into scripts. For some of the more simple aliases, here a selection:

    alias f='fastfetch -l none'
    alias vim='nvim'
    alias baloo='balooctl6'
    


  • With how many new Linux users we get recently, I don’t like this joke at all without a disclaimer. Yes yes, its your own fault if you execute commands without knowing what it does. But that should not punish someone by deleting every important personal file on the system.

    In case any reader don’t know, rm is a command to delete files and with the option rm -r everything recursively will be searched and deleted on the filesystem. Option -f (here bundled together as -rf) will never prompt for any non existing file. The / here means start from the root directory of you system, which in combination with the recursive option will search down everything, home folder included, and find every file. Normally this is protected todo, but the extra option --no-preserve-root makes sure this command is run with the root / path.

    Haha I know its funny. Until someone loses data. Jokes like these are harmful in my opinion.