fabric icon indicating copy to clipboard operation
fabric copied to clipboard

[Feature request]: Update ReadMe to replace pbpaste in examples

Open vpzed opened this issue 11 months ago • 2 comments

What do you need?

Suggestion: "pbpaste" is a Mac only command. Therefore, 95% of people viewing the README.md will not immediately understand the examples in "Example commands". Using a more common command like "cat input.txt ..." could improve understanding on first read for a larger audience. Thinking about reducing friction for new users.

vpzed avatar Feb 28 '24 22:02 vpzed

You can simulate pbpaste on Linux with the following aliased commands:

alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'

You must, of course, install xclip.

ptsiampas avatar Feb 28 '24 22:02 ptsiampas

I would suggest updating the setup.sh file.

i ran this stub on my Ubuntu desktop and it works fine so the theory is there.

#!/bin/bash
# Detect the Linux distribution
if [ -f /etc/os-release ]; then
  # Freedesktop.org and systemd
  . /etc/os-release
  if [[ $ID =~ ^(ubuntu|debian)$ ]]; then
    echo 'APT based you BITCHES!!!'
  elif [[ $ID =~ ^(centos|rhel|fedora)$ ]]; then
    echo 'RPM based you BITCHES!!!'
  fi
fi

This correctly identifies my Ubuntu desktop os-release

APT based you BITCHES!!!

I would suggest something along the lines off the following. I am unsure of my script; hence, it is here and not a PR. You would need to take into consideration the various flavours of Linux. Here, I just look at RPM or APT.

# Check if the config file contains an alias for the command
if grep -qE "alias $cmd=|alias $cmd =" "$config_file"; then
  # Detect the OS
  if [[ "$OSTYPE" == "darwin"* ]]; then
    # BSD sed (macOS)
    sed -i '' "/alias $cmd=/c\alias $cmd='$CMD_PATH'" "$config_file"
  else
    # GNU sed (Linux and others)
    # Detect the Linux distribution
    if [ -f /etc/os-release ]; then
      # Freedesktop.org and systemd
      . /etc/os-release
      if [[ $ID =~ ^(ubuntu|debian)$ ]]; then
        sudo apt-get update
        sudo apt-get install -y xclip
      elif [[ $ID =~ ^(centos|rhel|fedora)$ ]]; then
        sudo yum install -y xclip
      fi
    fi
    sed -i "/alias $cmd=/c\alias $cmd='$CMD_PATH'" "$config_file"
  fi
fi

We would then need to add the following two aliases to the aliases being added originally, but only for GNU systems.

alias pbcopy="xclip -selection clipboard"
alias pbcopy="xclip -selection clipboard"

twelsh37 avatar Feb 29 '24 12:02 twelsh37

Good recommendation on how to address this by @ptsiampas .

danielmiessler avatar Mar 03 '24 18:03 danielmiessler