Bartek Janicki stole a mobile phone, £120 in cash and medication after bursting into his victim's home.
The 20-year-old gained entry to the property in Thornfield Crescent after the resident heard a noise outside his door and mistook him for a door-to-door seller.
Janicki picked up a knife which was already in the property and brandished it at him on the afternoon of November 12.
Jedburgh Sheriff Court heard the Polish national became aggressive and told him to sit down.
Prosecutor India McLean said Janicki shouted he was going to rob the man and smash up his property - adding he knew he had drugs and wanted possession of them.
Police were alerted but Janicki continued ransacking the property until a neighbour disturbed him and the Police were alerted by a neighbour and he was later traced.
The court heard Janicki, who is currently serving a jail sentence on another matter and not due to be released until March 5, had a history with drugs.
Defence lawyer Liam Alexander, said it was his client's view that it would be easier to get help in prison.
Sheriff Peter Paterson told Janicki an unprovoked assault on an innocent man was an extremely serious offence. Coupled with his record, he said there was no option other than to jail him for 20 months which had been reduced from 30 months due to the guilty plea. He added that he did not know whether it would mean deportation back to Poland at the end of his sentence.
Janicki's sentence was backdated to November 13, when he was first remanded in custody in connection with the case.