Open phpstorm:// uri:s using xdg-open in Linux

I couldn’t get this to work properly on my Linux box; so I wrote a litte script that parses the uri scheme and launches phpstorm.

Script

<?php
$arg = $argv[1];
$parts = parse_url($arg);
$query = $parts['query'];
parse_str($query, $output);
$file = $output['file'];
$line = $output['line'];
$cmd = '/usr/bin/phpstorm --line ' . $line . ' ' . $file;
exec($cmd);

Then create a new file in ~/.local/share/applications/phpstorm-protocol.desktop

[Desktop Entry]
Name=PhpStorm Protocol Handler
Exec=/path/to/the/script %u
Terminal=false
Type=Application
MimeType=x-scheme-handler/phpstorm

Make it available, run:

update-desktop-database

and then register it with xdg-open

xdg-mime default phpstorm-protocol.desktop x-scheme-handler/phpstorm

Now, when you click a phpstorm:// link in your browser choose to open it with xdg-open.

What to do when grub os-prober fails to detect Windows

  1. Find out your Windows partitions UUID
    $ sudo blkid /dev/sda2
  2. Add a custom entry to /etc/grub.d/40_custom
    menuentry "Windows" --class windows --class os {
       insmod ntfs
       search --no-floppy --set=root --fs-uuid <UUID>
       ntldr /bootmgr
    }

    Replace <UUID> with UUID in step 1.

  3. Update your grub config
    $ sudo update-grub
    
    or
    
    $ sudo grub-mkconfig > /boot/grub/grub.cfg

Spara/återskapa körande Vagrant burkar vid avstängning/uppstart

Ett simpelt script som avslutar körande Vagrant burkar vid avstängning av din dator.

#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          something warm and fuzzy 
# Required-Start:    vboxdrv
# Required-Stop:     vboxdrv
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts suspended vagrant boxes and suspends running vagrant boxes
# Description:       
### END INIT INFO

# presumably only users with valid login shells are running vagrant boxes
validShells=$(cat /etc/shells | grep -v "#" | sed ':a;N;$!ba;s/\n/|/g')
userList=$(grep -E "$validShells" /etc/passwd | awk -F ':' ' { print $1 } ' | tr "\\n" " ")

case $1 in
  start)
    # loop thru every user
    for user in $userList; do
      # loop thru users suspended boxes
      for vm in $(su -c "vagrant global-status" $user 2>/dev/null | grep saved | awk ' { print $5 } '); do
        cd $vm >/dev/null
        su -c "vagrant up" $user
        su -c "vagrant status" $user > /dev/null # update global-status cache
      done
    done
  ;;
  stop)
    for user in $userList; do
      for vm in $(su -c "vagrant global-status" $user 2>/dev/null | grep running | awk ' { print $5 } '); do
        cd $vm > /dev/null
        su -c "vagrant suspend" $user
        su -c "vagrant status" $user > /dev/null # update global-status cache
      done
    done
  ;;
  status)
    for user in $userList; do
      echo "$user's vagrant box status"
      echo "------------------------------------------------------------------------"
      su -c "vagrant global-status 2> /dev/null" $user
      echo
      echo
    done
  ;;
  *)
    echo "Usage: $0 {start|stop|status}" >&2
    exit 1
  ;;
esac

exit 0

Installera med:

Redigera /etc/init.d/vagrant-boxes och klistra in ovanstående (eller ladda ner filen här). Sen kör du:

# update-rc.d vagrant-boxes defaults 99 01

99 är sekvensnumret, måste vara högre än det du har för Virtualbox (som använder 20, vilket är standard). Fungerar det exempelvis att spara boxarna vid avstängning men de inte startas igen vid start, dubbelkolla denna siffran. Andra siffran är i vilken ordning när du stänger av datorn, så 01 betyder att det är det första den gör (vilket kan vara bra).