Lovelace UI - Linux console editor

This is for the linux console junkies (like me) :slightly_smiling_face: who edit their files mostly in a terminal.

As the ui-lovelace.yaml gets bigger and bigger, i wrote a little script that greps the views from the file and starts the editor at the line number with the selected view.

The script (for example, save it in ~/ui_edit.sh and make it executable):

#!/bin/bash

userhome=$(eval echo ~$user)

# Path to ui-lovelace.yaml
lovelace_yaml="$userhome/.homeassistant/ui-lovelace.yaml"

# Command to start the editor and the option to jump to a line number
# For example, nano jumps to line with +linenumber
editor='nano -SE -T2 +'

prompt="Please select a view:"
# Grep the lovelace.yaml for lines starting a view ('  - title:')
options=( $(egrep '^ {2}- title:' -n $lovelace_yaml | awk '{print $4}') )

# Make some little menu with the views
PS3="$prompt "
echo '------------------------------------------------------'
select opt in "${options[@]}" "Quit" ; do
    if (( REPLY == 1 + ${#options[@]} )) ; then
        exit

    elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then
        echo  "You picked $opt ($REPLY)"
        break

    else
        echo "Invalid option. Try another one."
    fi
done

# Grep the lovelace.yaml once again for the '  title: <option>' and get the line number
lnum=$(egrep "^ {2}- title: ${opt}" -n $lovelace_yaml | awk -F ":" '{print $1}')

# Start the editor an jump to the line number
$editor$lnum $lovelace_yaml

I created an alias in .bashrc:

alias uiedit='~/ui_edit.sh'

Now when i type uiedit:

(ha) homeassi:~$ uiedit 
------------------------------------------------------
1) Home		    4) Mediaplayer     7) Cameras	 10) System
2) Wetter	    5) Milights	       8) Miscellaneous	 11) Quit
3) Baustelle	    6) Covers	       9) Tests
Please select a view: 9
You picked Tests (9)

The editor starts with the selected view

######################################################
### Tests
######################################################
  - title: Tests
    id: tests
    #theme: PmxMononight
    icon: mdi:flask-outline
    cards:

      - type: entities
        ...

Have fun!

3 Likes

Nice, I like it but cant get it to work.
copied the file made executable, changed lovelace.yaml path to mine but just says"Invalid option. Try another one."

Can you post the output of

egrep '^ {2}- title:' -n /path/to/your/ui-lovelace.yaml

thank you
I get nothing

Maybe you’re using icons only.

thank you
no i’ve identified my views like so:

- title: Info
  icon: mdi:information
  id: information

Thx @ciotlosm, but shouldn’t the β€˜title’ be required?

The script expects 2 spaces in front of β€œ- title:”, maybe thats the problem?

Thank you
I run
egrep β€˜^ {0}- title:’ -n /path/to/your/ui-lovelace.yaml

and got this

35: **- title:** Rooms

135: **- title:** Living

213: **- title:** Bose

275: **- title:** Info

442: **- title:** Location

517: **- title:** Server Status

Ok, definitely the way i have my yaml.

changed to

options=( $(egrep β€˜^ {0}- title:’ -n $lovelace_yaml | awk β€˜{print $3}’ ) )

and it works.

thank you for your help