I have always done this. I used to decorate cakes “back in the day”, and I have one particular straight glass that was reserved for this purpose.
Simply put your piping bag into the glass and fold over the edges. Fill, then lift out and twirl closed. Works like a charm.