Користувальницькькі налаштування

Налаштування сайту


software:os:linux:kde:browsers

Розбіжності

Тут показані розбіжності між вибраною ревізією та поточною версією сторінки.

Посилання на цей список змін

Наступна ревізія
Попередня ревізія
software:os:linux:kde:browsers [2025/12/04 12:38]
charon створено
software:os:linux:kde:browsers [2025/12/04 15:01] (поточний)
charon [Verify]
Рядок 2: Рядок 2:
 If you use 2 desktops in KDE, you can use different default browsers in these desktops. I like having Firefox as default browser for Personal desktop and Google Chrome for Work. If you use 2 desktops in KDE, you can use different default browsers in these desktops. I like having Firefox as default browser for Personal desktop and Google Chrome for Work.
  
-Create a shell script with logic for choosing +===== Create a shell script with logic for choosing =====
 Let's put it into //$HOME/scripts/smart-browser.sh//: Let's put it into //$HOME/scripts/smart-browser.sh//:
-<file smart-browser.sh>+<file bash smart-browser.sh>
 #!/usr/bin/env bash #!/usr/bin/env bash
  
-LOGFILE=/home/diz/temp/smartbrowser.log+# --- Configuration --- 
 +LOG_DIR="$HOME/temp/smartbrowser_logs" 
 +LOGFILE="$LOG_DIR/smartbrowser.log
 +# --------------------- 
 + 
 +# 1. Ensure the log directory exists 
 +mkdir -p "$LOG_DIR" 
 + 
 +# 2. Check and perform log rotation (clear file if not modified today) 
 +CURRENT_DATE=$(date +'%Y-%m-%d'
 + 
 +# Get the last modification date of the log file 
 +if [ -f "$LOGFILE" ]; then 
 +    # Use 'stat' command to get file modification time (platform specific, but common) 
 +    # The format specifier depends on the OS. On Linux (using GNU stat): 
 +    # %y: last modification time 
 +    # %Y: last modification time in seconds since epoch (simpler for comparisons if needed) 
 +    # We'll use the formatted date for simplicity: 
 +    LOG_DATE=$(stat -c '%Y' "$LOGFILE"
 +    LOG_MOD_DATE=$(date -d "@$LOG_DATE" +'%Y-%m-%d'
 +else 
 +    # If the file doesn't exist yet, treat its date as 'old' to trigger creation/touch 
 +    LOG_MOD_DATE="" 
 +fi 
 + 
 +if [[ "$LOG_MOD_DATE" != "$CURRENT_DATE" ]]; then 
 +    # Log file is from a previous day (or doesn't exist). Recreate/truncate it. 
 +    # The 'true > $LOGFILE' command effectively empties the file. 
 +    echo "[INFO] Log file rotated (previous date: $LOG_MOD_DATE)." > "$LOGFILE" 
 +    echo "---" >> "$LOGFILE" 
 +fi 
 +# The file is now either newly created, truncated, or from today. 
 + 
 +# 3. Get the current desktop number (KDE/KWin specific)
 current_desktop=$(qdbus org.kde.KWin /KWin currentDesktop) current_desktop=$(qdbus org.kde.KWin /KWin currentDesktop)
  
-printf '%s ' "$(date +'%Y-%m-%d %H:%M:%S')" >> "$LOGFILE" +# 4. Log the script call details 
-echo "Current desktop is $current_desktop, Args: $@" >> "$LOGFILE"+TIMESTAMP=$(date +'%Y-%m-%d %H:%M:%S')
  
 +printf '[%s] Current desktop: %s, Arguments: %s\n' "$TIMESTAMP" "$current_desktop" "$*" >> "$LOGFILE"
 +
 +# 5. Select and launch the browser based on the desktop number
 if [[ "$current_desktop" == "1" ]]; then if [[ "$current_desktop" == "1" ]]; then
 +    echo "[INFO] Launching Google Chrome..." >> "$LOGFILE"
     google-chrome "$@" >> "$LOGFILE" 2>&1     google-chrome "$@" >> "$LOGFILE" 2>&1
 elif [[ "$current_desktop" == "2" ]]; then elif [[ "$current_desktop" == "2" ]]; then
 +    echo "[INFO] Launching Firefox..." >> "$LOGFILE"
     firefox "$@" >> "$LOGFILE" 2>&1     firefox "$@" >> "$LOGFILE" 2>&1
 else else
 +    # Default to Firefox for all other desktops
 +    echo "[INFO] Launching Firefox (default)..." >> "$LOGFILE"
     firefox "$@" >> "$LOGFILE" 2>&1     firefox "$@" >> "$LOGFILE" 2>&1
 fi fi
 +
 +echo "---" >> "$LOGFILE"
 +
 +exit 0
 </file> </file>
 +Use file //$HOME/temp/smartbrowser_logs/smartbrowser.log// to view logs.
 +
 +===== Create .desktop file =====
 +Create a file //~/.local/share/applications/smart-browser.desktop//:
 +<file smart-browser.desktop>
 +[Desktop Entry]
 +Version=1.0
 +Name=Smart Browser
 +Comment=Context-aware browser launcher
 +Exec=bash -c "$HOME/scripts/smart-browser.sh %u"
 +Icon=web-browser
 +Terminal=false
 +Type=Application
 +Categories=Network;WebBrowser;
 +MimeType=text/html;text/xml;application/xhtml+xml;x-scheme-handler/http;x-scheme-handler/https;
 +</file>
 +
 +===== Set as default browser =====
 +<code bash>
 +xdg-settings set default-web-browser smart-browser.desktop
 +xdg-mime default smart-browser.desktop x-scheme-handler/http x-scheme-handler/https
 +</code>
 +
 +===== Verify (optional) =====
 +<code bash>
 +xdg-settings get default-web-browser
 +xdg-mime query default x-scheme-handler/https
 +xdg-mime query default x-scheme-handler/http
 +xdg-open 'http://example.com'
 +xdg-open 'https://www.google.com'
 +</code>
software/os/linux/kde/browsers.1764844735.txt.gz · Востаннє змінено: 2025/12/04 12:38 повз charon