summaryrefslogtreecommitdiffstats
path: root/scripts/scrolling-title.nix
blob: 91d0838ad48264a3be4fe2045c2e720974c8edae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{ pkgs }:
pkgs.writeShellApplication {
  name = "scrolling-title";
  runtimeInputs = with pkgs; [ mpc coreutils ];
  text = ''
    WIDTH=16
    PADDING="          "
    
    RAW_STR=$(mpc current)
    
    if [ -z "$RAW_STR" ]; then
      echo "Stopped"
      exit 0
    fi

    STR="$RAW_STR$PADDING"
    LEN=''${#STR} 

    T=$(date +%s)
    INDEX=$(( T % LEN ))

    # Output the scrolled window
    DOUBLE_STR="''$STR''$STR"
    echo "''${DOUBLE_STR:''$INDEX:''$WIDTH}"
'';
}