sebastiancarlos

joined 1 year ago
 
 
 
 

Source code:

#!/usr/bin/env bash

# runasm - Assemble, link, and run multiple assembly files, then delete them.
if [[ $# -eq 0 ]]; then
    echo "Usage: runasm  [ ...]"
    echo "  - Assemble, link, and run multiple assembly files, then delete them."
    echo "  - Name of executable is the name of the first file without extension."
    exit 1
fi

object_files=()
executable_file=${1%.*}

for assembly_file in "$@"; do
    # Avengers, assemble!
    object_file="${assembly_file%.*}.o"
    as "${assembly_file}" -o "${object_file}"
    if [[ $? -ne 0 ]]; then
        exit 1
    fi
    object_files+=("${object_file}")
done

# Link
ld "${object_files[@]}" -o "${executable_file}"
if [[ $? -ne 0 ]]; then
    exit 1
fi

# Run, remove created files, and return exit code
./"${executable_file}"
exit_code=$?
rm "${object_files[@]}" "${executable_file}" > /dev/null 2>&1
exit "${exit_code}"
 
[–] [email protected] 1 points 10 months ago

Cool, thanks! Look like there are things like xrandr for Wayland with this functionality. the burn-in is not so bad right now but I'll keep this in mind.

[–] [email protected] 2 points 10 months ago

Yes! I use it all the time. No idea why it's not more popular

[–] [email protected] 4 points 10 months ago (2 children)

.bashrc:

# Prompt
# "Make it simple, just the dollar sign"
# "Say no more, fam"
# - if error code is not 0, then prepend [N] where N is the error code
# - if user is root, use red and #
blue='\e[34m'
red='\e[31m'
bold='\e[1m'
reset='\e[0m'
PS1='$( status=$?; [ $status -ne 0 ] && echo "[$status] ")\['"$blue""$bold"'\]$\['"$reset"'\] '

if [[ $EUID -eq 0 ]]; then
  PS1='$( status=$?; [ $status -ne 0 ] && echo "[$status] ")\['"$red""$bold"'\]#\['"$reset"'\] '
fi

.inputrc:

# vi mode, change to 'emacs' here if you prefer
set editing-mode vi

# vi INSERT prompt
set vi-ins-mode-string "\1\e[30;44m\2 INS \1\e[0m\2 "

# vi NORMAL prompt
set vi-cmd-mode-string "\1\e[30;47m\2 NOR \1\e[0m\2 "
[–] [email protected] 1 points 10 months ago* (last edited 10 months ago)

answered in post. btw it seems this is a Sway only issue, so it makes sense it's ok in i3

[–] [email protected] 1 points 10 months ago

answered in post

[–] [email protected] 1 points 10 months ago (3 children)

answered in post

 

I need extremely small tiling windows, say something with only a width/height of 10px. However, by experimentation I found that my window manager Sway (and likely also i3) has a hard-coded minimum height of 60px and minimum width of 100px.

So, dear Linux gurus, do you know of a window manager with configurable minimum tiling window size? Or with no minimum at all? Bonus point for running natively on Wayland.

Edit: Found the culprit in the sway codebase:

sway/include/sway/tree/node.h

#define MIN_SANE_W 100
#define MIN_SANE_H 60

In short, I am not sane.

These constants are not used much in the codebase, so it shouldn't hurt to change it and compile from source. I will report results. Btw I opened an issue to see if they can be made configurable. Plus, some code archaeology suggests that this is not an issue in i3.

Thanks for your suggestions. Some, like Hyprland and dwl, sound promising, but I'll try to make it work with Sway first.

Why do I need this, you ask? It's a bit of a secret, but I've been working for about two years on a custom "operating system", or rather a suite of productivity tools unlike anything seen before. I'm about to finish it, but one of my last requirements to make it all click is a tiling window manager that is both extremely minimal and extremely customizable. It will eventually be released as free software for the benefit, amusement, and horror of everyone.

Also the top 20px of my screen has burn-in and I want to declare it unusable at the window manager level. You see, I use Linux not only to flex, but also to live frugally.

Edit 2: Compiling from source worked. Patch here:

diff --unified --recursive --text sway-git/include/sway/tree/node.h sway-git.new/include/sway/tree/node.h
***
sway-git/include/sway/tree/node.h	2023-10-23 19:21:15.915536904 +0200
+++ sway-git.new/include/sway/tree/node.h	2023-10-23 19:30:18.638894754 +0200
@@ -4,8 +4,8 @@
 #include 
 #include "list.h"
 
-#define MIN_SANE_W 100
-#define MIN_SANE_H 60
+#define MIN_SANE_W 20
+#define MIN_SANE_H 20
 
 struct sway_root;
 struct sway_output;
[–] [email protected] 2 points 10 months ago

Both are incomplete, but the article is no longer paywalled

[–] [email protected] 7 points 11 months ago
61
submitted 11 months ago* (last edited 11 months ago) by [email protected] to c/[email protected]
 

Source code

#!/usr/bin/env bash

# colorcat
# - cats a file, but if any line contains N hex colors, it appends the colors
#   (rendered as ansi escape sequences) to the end of the line.
# - input can be stdin, a file, or a hex color in plain text
if [[ "$#" -eq 1 && ! -f "$1" ]]; then
  echo "$1"
else
  cat "$@"
fi | while read -r line; do
  colors=""
  for word in $line; do
    if [[ "$word" =~ ^[^A-Fa-f0-9]*#?([A-Fa-f0-9]{6})[^A-Fa-f0-9]*$ ]]; then
      hex=${BASH_REMATCH[1]}
      r=$((16#${hex:0:2}))
      g=$((16#${hex:2:2}))
      b=$((16#${hex:4:2}))
      truecolor="\033[48;2;${r};${g};${b}m"
      reset="\033[0m"
      colors="${colors}${truecolor}  ${reset} "
    fi
  done
    echo -e "$line $colors" 
done
11
submitted 11 months ago* (last edited 11 months ago) by [email protected] to c/[email protected]
 

Source code:

# source of truth for URL aliases
# - used by url-alias-setup and url-alias
# - can be modified to add new aliases
declare -A __url_alias=(
  ["g"]="https://google.com"
  ["r"]="https://reddit.com"
  ["h"]="https://news.ycombinator.com"
)

# url-alias
# - print the current URL aliases
function url-alias () {
  local green="\033[32m"
  local cyan="\033[36m"
  local reset="\033[0m"

  echo "${green}URL aliases:${reset}"
  for alias in "${!__url_alias[@]}"; do
    echo "${cyan}${alias}${reset} -> ${__url_alias[${alias}]}"
  done

  echo "${green}To add new aliases, edit the ${cyan}__url_alias${green} array and run ${cyan}url-alias-setup${reset}"
}

# return either 'linux' or 'macos'
function get_platform () {
  case "$(uname -s)" in
    Darwin)
      echo "macos"
      ;;
    Linux)
      echo "linux"
      ;;
    *)
      echo "unsupported platform"
      exit 1
      ;;
  esac
}
platform=$(get_platform)

# url-alias-setup
# - sets up URL aliases
# - this is done by modifying the /etc/hosts file and the nginx configuration
# - if changes are made, nginx is (re)started
function url-alias-setup () {
  # nginx config (platform dependent) 
  if [[ "$platform" == "macos" ]]; then
    local nginx_config="/usr/local/etc/nginx/nginx.conf"
  else
    local nginx_config="/etc/nginx/nginx.conf"
  fi

  # create new nginx config and hosts file
  local new_hosts=""
  read -r -d '' new_nginx_config << 'EOF'
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
EOF
  
  for alias in "${!__url_alias[@]}"; do
    local url="${__url_alias[$alias]}"

    new_hosts="${new_hosts}\n127.0.0.1 ${alias}"

    read -r -d '' server_blocks << EOF
    server {
        listen       80;
        server_name  ${alias};
        location / {
          rewrite ^ ${url} permanent;
        }
    }
EOF
    new_nginx_config="${new_nginx_config}\n    ${server_blocks}"
  done
  new_nginx_config="${new_nginx_config}\n}"
  
  # replace files
  # if file already exists, prompt user to overwrite
  echo "Saving new nginx config and hosts file..."
  if [[ -f "${nginx_config}" ]]; then
    echo "File ${nginx_config} already exists. Overwrite? (y/n)"
    read -r overwrite
    if [[ "${overwrite}" != "y" ]]; then
      echo "Aborting..."
      return 1
    fi
  fi
  echo -e "${new_nginx_config}" | sudo tee "${nginx_config}" > /dev/null
  if [[ -f "/etc/hosts" ]]; then
    echo "File /etc/hosts already exists. Overwrite? (y/n)"
    read -r overwrite
    if [[ "${overwrite}" != "y" ]]; then
      echo "Aborting..."
      return 1
    fi
  fi
  echo -e "${new_hosts}" | sudo tee /etc/hosts > /dev/null

  # start or restart nginx
  echo "Restarting nginx..."
  if [[ "$platform" == "macos" ]]; then
    nginx -s reload
  else
    sudo systemctl restart nginx
  fi
}
[–] [email protected] 1 points 11 months ago

Looks like you sshd into my working titles

[–] [email protected] 23 points 1 year ago (7 children)

It's also traditional to eat raw meat, but we discovered fire at some point.

[–] [email protected] 27 points 1 year ago* (last edited 1 year ago) (10 children)

You also don’t need the dash for the short options.

True, but I refuse to entertain such a non-standard option format. It's already enough to tolerate find's.

 
[–] [email protected] 14 points 1 year ago (1 children)
view more: ‹ prev next ›