Skip to content

Instantly share code, notes, and snippets.

@funasoul
Last active October 15, 2022 17:22

Revisions

  1. funasoul revised this gist Oct 15, 2022. No changes.
  2. funasoul created this gist Oct 15, 2022.
    18 changes: 18 additions & 0 deletions get_resolution.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    #!/usr/bin/env zsh

    _has () {
    return $( whence $1 &>/dev/null )
    }

    getresolution () {
    # returns current resolution
    if [[ "$OSTYPE" == "darwin"* ]]; then
    system_profiler SPDisplaysDataType | awk '/Resolution:/{print $2 "x" $4}'
    elif _has xrandr; then
    xrandr | awk '/\*/{print $1}'
    elif _has xdpyinfo; then
    xdpyinfo | awk '/dimensions/{print $2}'
    fi
    }

    getresolution