keeping straight wall bed leg with shelf

if it is weighted right I think it could be accomplished with gravity.