Sample Header Ad - 728x90

waybar custom module argument not found

0 votes
0 answers
33 views
i just installed hyprland yesterday in ubuntu 24.04 (first time), i want to add a removable drives menu in the waybar, and after searching around i came out with this custom module:
"custom/mounted-drives": {
    "format": " {}",
    "return-type": "json",
    "exec": "~/.config/waybar/scripts/mounted_removable_drives.sh",
    "interval": 5,
    "on-click": "xdg-open {alt}",
    "on-click-right": "~/.config/waybar/scripts/unmount_drive.sh {alt}"
},
Since I'm new to this I must be doing something wrong... the scripts I'm using are: mounted_removable_drives.sh:
#!/bin/bash

# This script detects mounted removable drives (including rclone mounts)

# Function to check if a mount point is a removable drive
is_removable() {
  local source="$1"
  local target="$2"
  local fstype="$3"
  local options="$4"

  # Exclude common system mounts
  case "$target" in
  / | /boot* | /dev* | /proc* | /sys* | /run* | /snap* | /var/lib/snapd/snap | /tmp* | /home/*/.local/share/flatpak/runtime)
    return 1
    ;;
  esac

  case "$fstype" in
  tmpfs | devtmpfs | proc | sysfs | cgroup2 | overlay | squashfs)
    return 1
    ;;
  fuse.rclone | fuse.sshfs | fuse.gvfsd-fuse)
    # Include FUSE mounts like rclone, sshfs, gvfsd-fuse
    return 0
    ;;
  ext4 | vfat | ntfs | exfat | btrfs | xfs)
    # Consider mounts under /media or /mnt as potentially removable
    if [[ "$target" == /media/* || "$target" == /mnt/* ]]; then
      return 0
    fi
    # Check for common removable drive options (e.g., noauto, users, umask, uid, gid)
    if [[ "$options" =~ "noauto" || "$options" =~ "users" || "$options" =~ "umask" || "$options" =~ "uid" || "$options" =~ "gid" ]]; then
      return 0
    fi
    ;;
  esac

  return 1
}

# Get mount information in JSON format
mount_info=$(findmnt -lo SOURCE,TARGET,FSTYPE,OPTIONS,USED --json)

# Parse JSON and build Waybar output
output="[]"
if [[ -n "$mount_info" ]]; then
  mounted_drives=()
  # Use jq to parse and filter
  while IFS=$'\n' read -r mount_point; do
    if [[ -n "$mount_point" ]]; then
      source=$(echo "$mount_point" | jq -r '.source')
      target=$(echo "$mount_point" | jq -r '.target')
      fstype=$(echo "$mount_point" | jq -r '.fstype')
      options=$(echo "$mount_point" | jq -r '.options')
      used=$(echo "$mount_point" | jq -r '.used')

      if is_removable "$source" "$target" "$fstype" "$options"; then
        # Clean up source for display
        display_source=$(basename "$source")
        if [[ "$fstype" == "fuse.rclone" ]]; then
          display_source="Rclone: ${display_source}"
        elif [[ "$fstype" == "fuse.sshfs" ]]; then
          display_source="SSHFS: ${display_source}"
        elif [[ "$fstype" == "fuse.gvfsd-fuse" ]]; then
          display_source="GVFS: ${display_source}"
        fi

        # Format used space
        formatted_used=""
        if [[ "$used" != "null" && "$used" != "" ]]; then
          formatted_used=" (${used} used)"
        fi

        mounted_drives+=("$(jq -n --arg text "$display_source" --arg tooltip "Source: $source\nTarget: $target\nType: $fstype\nOptions: $options$formatted_used" --arg alt "$target" --arg class "removable-drive" '{text: $text, tooltip: $tooltip, alt: $alt, class: $class}')")
      fi
    fi
  done &1

if [ $? -eq 0 ]; then
    notify-send "Drive Unmounted" "Successfully unmounted $MOUNT_POINT"
else
    notify-send "Unmount Failed" "Failed to unmount $MOUNT_POINT. Check logs for details."
fi
Asked by kurokirasama (303 rep)
Jul 14, 2025, 08:39 PM
Last activity: Jul 16, 2025, 01:39 AM