I heard from many preachings that whatever the person thinks while dying, will eventually decide the persons next life.
Is it true?
BG 8.6 — Also [when] the body is left remembering whatever "Nature" at the end, O son of Kunti, [it] always approaches towards establishing those nature(s) only.
This is further confirmed by below verse, which though said in the context of the Yogi-s, is applicable to all. i.e. we carry forward the practices/samskAra-s of our past births.
BG 6.44 - For, by that very past practice, he is carried forward even in spite of himself! Even a seeker of Yoga transcends the result of the performance of Vedic rituals! (tr: Gambhirananda)
Also refer my answer in: According to Hinduism, what do we carry into afterlife and next birth?
Out Mann / mind is carried to the next life.
Also as per Gita, if a person dies thoughtless, then attains liberation. The other way of calling thoughtless mind is, the mind which is concentrated in the thoughts of "Me" alone. Refer BG 8.5 in this answer's context.
Actually it's Yes and No. If you always have happy thoughts and you were a good person spiritually then in your last moment also you would be good and hence the conjecture holds true, and on the other hand you are a wicked man during your lifetime and since we don't know when we will die, its highly likely that a wicked man has wicked thoughts when he dies, hence its how you live that defines the thoughts you have when you die. There is a Pasuram in Tamil by Periyazhwar that says I'll say the gods name now and that you consider it as my last words as I die, but if you analyse it, he goes to say that I'll say it now and if I have the habit of saying it always only will I be able to think of you in my last moment as well.
Periyazhvar Thirumozhi 423
The meek surrender to You, confident that You will save them when their strengths are gone; I am of no merit, yet I surrender unto You, with unshakable faith that You will save me, like You saved GajEndran. O! the Lord of Sri Rangam, slumbering upon the snake-bed, when old age is upon me, I won't think of You; So, let me surrender unto You, right here and now
One example for this is mentioned in Śrīmad-Bhāgavatam (Bhāgavata Purāṇa) » Canto 5: The Creative Impetus
Although he was able to give up his opulent kingdom, he became attached to the deer. Thus he fell down from his mystic yoga practice. Once when the deer was absent, Mahārāja Bharata was so disturbed that he began to search for it. While searching and lamenting the deer’s absence, Mahārāja Bharata fell down and died. Because his mind was fully absorbed thinking of the deer, he naturally took his next birth from the womb of a deer.
Yes, it is told by Shandilya in Chhandogya Upanishad:
सर्वं खल्विदं ब्रह्म तज्जलानिति शान्त उपासीत ।
अथ खलु क्रतुमयः पुरुषो यथाक्रतुरस्मिꣳल्लोके पुरुषो भवति तथेतः प्रेत्य भवति स क्रतुं कुर्वीत ॥ ३.१४.१॥
III-xiv-1: Verily, all this universe is Brahman. From Him do all things originate, into Him do they dissolve and by Him are they sustained. On Him should one meditate in tranquility. For as is one's faith, such indeed one is; and as is one's faith in this world, such one becomes on departing hence. Let one, therefore, cultivate faith.
अन्ते मति: सा गति: |
Yes. It is true.
That's why 'Pitamaha Bheeshma' requested Lord Krishna to be in front of him and
while watching him and chanting 'Vishnusahasranama', he left his mortal body.
(ref.:- Mahabharata -
Yuddha Parwa Anushasana Parva).