Тут показані розбіжності між вибраною ревізією та поточною версією сторінки.
| Наступна ревізія | Попередня ревізія | ||
|
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 // | Let's put it into // | ||
| - | <file smart-browser.sh> | + | < |
| # | # | ||
| - | LOGFILE=/home/diz/ | + | # --- Configuration --- |
| + | LOG_DIR="$HOME/temp/ | ||
| + | LOGFILE=" | ||
| + | # --------------------- | ||
| + | |||
| + | # 1. Ensure the log directory exists | ||
| + | mkdir -p " | ||
| + | |||
| + | # 2. Check and perform log rotation (clear file if not modified today) | ||
| + | CURRENT_DATE=$(date +' | ||
| + | |||
| + | # Get the last modification date of the log file | ||
| + | if [ -f " | ||
| + | # Use ' | ||
| + | # 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 ' | ||
| + | LOG_MOD_DATE=$(date -d " | ||
| + | else | ||
| + | # If the file doesn' | ||
| + | LOG_MOD_DATE="" | ||
| + | fi | ||
| + | |||
| + | if [[ " | ||
| + | # Log file is from a previous day (or doesn' | ||
| + | # The 'true > $LOGFILE' | ||
| + | echo " | ||
| + | echo " | ||
| + | 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 +' | + | # 4. Log the script call details |
| - | echo " | + | TIMESTAMP=$(date +' |
| + | printf '[%s] Current desktop: %s, Arguments: %s\n' " | ||
| + | |||
| + | # 5. Select and launch the browser based on the desktop number | ||
| if [[ " | if [[ " | ||
| + | echo " | ||
| google-chrome " | google-chrome " | ||
| elif [[ " | elif [[ " | ||
| + | echo " | ||
| firefox " | firefox " | ||
| else | else | ||
| + | # Default to Firefox for all other desktops | ||
| + | echo " | ||
| firefox " | firefox " | ||
| fi | fi | ||
| + | |||
| + | echo " | ||
| + | |||
| + | exit 0 | ||
| </ | </ | ||
| + | Use file // | ||
| + | |||
| + | ===== Create .desktop file ===== | ||
| + | Create a file // | ||
| + | <file smart-browser.desktop> | ||
| + | [Desktop Entry] | ||
| + | Version=1.0 | ||
| + | Name=Smart Browser | ||
| + | Comment=Context-aware browser launcher | ||
| + | Exec=bash -c " | ||
| + | Icon=web-browser | ||
| + | Terminal=false | ||
| + | Type=Application | ||
| + | Categories=Network; | ||
| + | MimeType=text/ | ||
| + | </ | ||
| + | |||
| + | ===== Set as default browser ===== | ||
| + | <code bash> | ||
| + | xdg-settings set default-web-browser smart-browser.desktop | ||
| + | xdg-mime default smart-browser.desktop x-scheme-handler/ | ||
| + | </ | ||
| + | |||
| + | ===== Verify (optional) ===== | ||
| + | <code bash> | ||
| + | xdg-settings get default-web-browser | ||
| + | xdg-mime query default x-scheme-handler/ | ||
| + | xdg-mime query default x-scheme-handler/ | ||
| + | xdg-open ' | ||
| + | xdg-open ' | ||
| + | </ | ||